Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Liu <[email protected]>
  • Loading branch information
austin362667 committed Mar 27, 2024
1 parent 804179e commit cff01cf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
23 changes: 23 additions & 0 deletions flyteadmin/pkg/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package errors
import (
"context"
"errors"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/wI2L/jsondiff"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -54,6 +56,27 @@ func TestNewIncompatibleClusterError(t *testing.T) {
assert.True(t, ok)
}

func TestJsonDifferError(t *testing.T) {
oldSpec := map[string]int{
"one": 1,
"two": 2,
"three": 3,
"four": 4,
"five": 5,
}
newSpec := map[string]int{
"five": 5,
"four": 0,
"three": 3,
"two": 2,
"one": 1,
}
diff, _ := jsondiff.Compare(oldSpec, newSpec)
rdiff, _ := jsondiff.Compare(newSpec, oldSpec)
rs := compareJsons(diff, rdiff)
assert.Equal(t, "\t\t- /four: 4 -> 0", strings.Join(rs, "\n"))
}

func TestNewTaskExistsDifferentStructureError(t *testing.T) {
req := &admin.TaskCreateRequest{
Id: &identifier,
Expand Down
7 changes: 4 additions & 3 deletions flyteadmin/pkg/manager/impl/launch_plan_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ func (m *LaunchPlanManager) CreateLaunchPlan(
if bytes.Equal(existingLaunchPlanModel.Digest, launchPlanDigest) {
return nil, errors.NewLaunchPlanExistsIdenticalStructureError(ctx, &request)
}
existingLaunchPlan, err2 := transformers.FromLaunchPlanModel(existingLaunchPlanModel)
if err2 != nil {
return nil, err2
existingLaunchPlan, transformerErr := transformers.FromLaunchPlanModel(existingLaunchPlanModel)
if transformerErr != nil {
logger.Errorf(ctx, "failed to transform launch plan from launch plan model")
return nil, transformerErr
}
// A launch plan exists with different structure
return nil, errors.NewLaunchPlanExistsDifferentStructureError(ctx, &request, existingLaunchPlan.Spec, launchPlan.Spec)
Expand Down
7 changes: 4 additions & 3 deletions flyteadmin/pkg/manager/impl/task_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ func (t *TaskManager) CreateTask(
if bytes.Equal(taskDigest, existingTaskModel.Digest) {
return nil, errors.NewTaskExistsIdenticalStructureError(ctx, &request)
}
existingTask, err2 := transformers.FromTaskModel(*existingTaskModel)
if err2 != nil {
return nil, err2
existingTask, transformerErr := transformers.FromTaskModel(*existingTaskModel)
if transformerErr != nil {
logger.Errorf(ctx, "failed to transform task from task model")
return nil, transformerErr
}
return nil, errors.NewTaskExistsDifferentStructureError(ctx, &request, existingTask.Closure.GetCompiledTask(), compiledTask)
}
Expand Down
7 changes: 4 additions & 3 deletions flyteadmin/pkg/manager/impl/workflow_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ func (w *WorkflowManager) CreateWorkflow(
if bytes.Equal(workflowDigest, existingWorkflowModel.Digest) {
return nil, errors.NewWorkflowExistsIdenticalStructureError(ctx, &request)
}
existingWorkflow, err2 := transformers.FromWorkflowModel(existingWorkflowModel)
if err2 != nil {
return nil, err2
existingWorkflow, transformerErr := transformers.FromWorkflowModel(existingWorkflowModel)
if transformerErr != nil {
logger.Errorf(ctx, "failed to transform workflow from workflow model")
return nil, transformerErr
}
// A workflow exists with different structure
return nil, errors.NewWorkflowExistsDifferentStructureError(ctx, &request, existingWorkflow.Closure.GetCompiledWorkflow(), workflowClosure.GetCompiledWorkflow())
Expand Down

0 comments on commit cff01cf

Please sign in to comment.