From b6bf32d5247c476d6d1b4412eb8ff4f434b1a603 Mon Sep 17 00:00:00 2001 From: Joe Eschen Date: Mon, 25 Sep 2023 09:24:19 -0700 Subject: [PATCH] code review: patched up tests, added testutils function, patched up if checks Signed-off-by: Joe Eschen --- pkg/manager/impl/testutils/mock_requests.go | 4 ++++ pkg/repositories/transformers/workflow.go | 4 ++-- pkg/repositories/transformers/workflow_test.go | 12 +++--------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pkg/manager/impl/testutils/mock_requests.go b/pkg/manager/impl/testutils/mock_requests.go index fda9482e1..c0e765f3e 100644 --- a/pkg/manager/impl/testutils/mock_requests.go +++ b/pkg/manager/impl/testutils/mock_requests.go @@ -300,3 +300,7 @@ func GetWorkflowRequestInterfaceBytes() []byte { bytes, _ := proto.Marshal(GetWorkflowRequest().Spec.Template.Interface) return bytes } + +func GetWorkflowRequestInterface() *core.TypedInterface { + return GetWorkflowRequest().Spec.Template.Interface +} diff --git a/pkg/repositories/transformers/workflow.go b/pkg/repositories/transformers/workflow.go index c45bdc501..ac0a7fbaf 100644 --- a/pkg/repositories/transformers/workflow.go +++ b/pkg/repositories/transformers/workflow.go @@ -49,10 +49,10 @@ func FromWorkflowModel(workflowModel models.Workflow) (admin.Workflow, error) { } var workflowInterface core.TypedInterface - if workflowModel.TypedInterface != nil && len(workflowModel.TypedInterface) > 0 { + if len(workflowModel.TypedInterface) > 0 { err = proto.Unmarshal(workflowModel.TypedInterface, &workflowInterface) if err != nil { - return admin.Workflow{}, errors.NewFlyteAdminErrorf(codes.Internal, fmt.Sprintf("failed to unmarshal workflow %v inputs", workflowModel.ID)) + return admin.Workflow{}, errors.NewFlyteAdminErrorf(codes.Internal, fmt.Sprintf("failed to unmarshal workflow %v interface", workflowModel.ID)) } } diff --git a/pkg/repositories/transformers/workflow_test.go b/pkg/repositories/transformers/workflow_test.go index 916a01763..ac35b4735 100644 --- a/pkg/repositories/transformers/workflow_test.go +++ b/pkg/repositories/transformers/workflow_test.go @@ -134,8 +134,7 @@ func TestFromWorkflowModels(t *testing.T) { Version: "version a", }, workflowList[0].Id)) - var workflowInterface0 core.TypedInterface - err = proto.Unmarshal(workflowModels[0].TypedInterface, &workflowInterface0) + workflowInterface := testutils.GetWorkflowRequestInterface() assert.NoError(t, err) assert.True(t, proto.Equal(&admin.WorkflowClosure{ @@ -143,7 +142,7 @@ func TestFromWorkflowModels(t *testing.T) { CompiledWorkflow: &core.CompiledWorkflowClosure{ Primary: &core.CompiledWorkflow{ Template: &core.WorkflowTemplate{ - Interface: &workflowInterface0, + Interface: workflowInterface, }, }, }, @@ -157,17 +156,12 @@ func TestFromWorkflowModels(t *testing.T) { Version: "version b", }, workflowList[1].Id)) - // Expected to be nil - var workflowInterface1 core.TypedInterface - err = proto.Unmarshal(workflowModels[1].TypedInterface, &workflowInterface1) - assert.NoError(t, err) - assert.True(t, proto.Equal(&admin.WorkflowClosure{ CreatedAt: createdAtBProto, CompiledWorkflow: &core.CompiledWorkflowClosure{ Primary: &core.CompiledWorkflow{ Template: &core.WorkflowTemplate{ - Interface: &workflowInterface1, + Interface: &core.TypedInterface{}, }, }, },