Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
Signed-off-by: Yee Hing Tong <[email protected]>
  • Loading branch information
wild-endeavor committed Oct 2, 2022
1 parent f7bdfca commit 8848d1e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/manager/impl/resources/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package resources

import (
"context"

runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"

// pkg/runtime/interfaces/application_configuration.go
runtimeMocks "github.com/flyteorg/flyteadmin/pkg/runtime/mocks"
"testing"

runtimeMocks "github.com/flyteorg/flyteadmin/pkg/runtime/mocks"

"github.com/flyteorg/flyteadmin/pkg/errors"
"google.golang.org/grpc/codes"

Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/impl/util/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"errors"
"fmt"
"github.com/golang/protobuf/ptypes/wrappers"
"strings"
"testing"

"github.com/golang/protobuf/ptypes/wrappers"

"github.com/flyteorg/flyteadmin/pkg/common"
commonMocks "github.com/flyteorg/flyteadmin/pkg/common/mocks"
flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
Expand Down
60 changes: 60 additions & 0 deletions pkg/manager/impl/validation/project_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,63 @@ func TestValidateProjectAndDomainNotFound(t *testing.T) {
"flyte-project", "domain")
assert.EqualError(t, err, "failed to validate that project [flyte-project] and domain [domain] are registered, err: [project [flyte-project] not found]")
}

func TestValidateProjectDb(t *testing.T) {
mockRepo := repositoryMocks.NewMockRepository()
t.Run("base case", func(t *testing.T) {
mockRepo.ProjectRepo().(*repositoryMocks.MockProjectRepo).GetFunction = func(
ctx context.Context, projectID string) (models.Project, error) {
assert.Equal(t, projectID, "flyte-project-id")
activeState := int32(admin.Project_ACTIVE)
return models.Project{State: &activeState}, nil
}
err := ValidateProjectForUpdate(context.Background(), mockRepo, "flyte-project-id")

assert.Nil(t, err)
})

t.Run("error getting", func(t *testing.T) {
mockRepo.ProjectRepo().(*repositoryMocks.MockProjectRepo).GetFunction = func(
ctx context.Context, projectID string) (models.Project, error) {

return models.Project{}, errors.New("missing")
}
err := ValidateProjectForUpdate(context.Background(), mockRepo, "flyte-project-id")
assert.Error(t, err)
})

t.Run("error archived", func(t *testing.T) {
mockRepo.ProjectRepo().(*repositoryMocks.MockProjectRepo).GetFunction = func(
ctx context.Context, projectID string) (models.Project, error) {
state := int32(admin.Project_ARCHIVED)
return models.Project{State: &state}, nil
}
err := ValidateProjectForUpdate(context.Background(), mockRepo, "flyte-project-id")
assert.Error(t, err)
})
}

func TestValidateProjectExistsDb(t *testing.T) {
mockRepo := repositoryMocks.NewMockRepository()
t.Run("base case", func(t *testing.T) {
mockRepo.ProjectRepo().(*repositoryMocks.MockProjectRepo).GetFunction = func(
ctx context.Context, projectID string) (models.Project, error) {
assert.Equal(t, projectID, "flyte-project-id")
activeState := int32(admin.Project_ACTIVE)
return models.Project{State: &activeState}, nil
}
err := ValidateProjectExists(context.Background(), mockRepo, "flyte-project-id")

assert.Nil(t, err)
})

t.Run("error getting", func(t *testing.T) {
mockRepo.ProjectRepo().(*repositoryMocks.MockProjectRepo).GetFunction = func(
ctx context.Context, projectID string) (models.Project, error) {

return models.Project{}, errors.New("missing")
}
err := ValidateProjectExists(context.Background(), mockRepo, "flyte-project-id")
assert.Error(t, err)
})
}

0 comments on commit 8848d1e

Please sign in to comment.