|
| 1 | +package create |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/flyteorg/flytectl/cmd/config" |
| 7 | + "github.com/flyteorg/flytectl/cmd/testutils" |
| 8 | + "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" |
| 9 | + "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" |
| 10 | + |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | + "github.com/stretchr/testify/mock" |
| 13 | + "google.golang.org/protobuf/types/known/timestamppb" |
| 14 | +) |
| 15 | + |
| 16 | +// This function needs to be called after testutils.Steup() |
| 17 | +func createExecutionSetup() { |
| 18 | + ctx = testutils.Ctx |
| 19 | + cmdCtx = testutils.CmdCtx |
| 20 | + mockClient = testutils.MockClient |
| 21 | + sortedListLiteralType := core.Variable{ |
| 22 | + Type: &core.LiteralType{ |
| 23 | + Type: &core.LiteralType_CollectionType{ |
| 24 | + CollectionType: &core.LiteralType{ |
| 25 | + Type: &core.LiteralType_Simple{ |
| 26 | + Simple: core.SimpleType_INTEGER, |
| 27 | + }, |
| 28 | + }, |
| 29 | + }, |
| 30 | + }, |
| 31 | + } |
| 32 | + variableMap := map[string]*core.Variable{ |
| 33 | + "sorted_list1": &sortedListLiteralType, |
| 34 | + "sorted_list2": &sortedListLiteralType, |
| 35 | + } |
| 36 | + |
| 37 | + task1 := &admin.Task{ |
| 38 | + Id: &core.Identifier{ |
| 39 | + Name: "task1", |
| 40 | + Version: "v2", |
| 41 | + }, |
| 42 | + Closure: &admin.TaskClosure{ |
| 43 | + CreatedAt: ×tamppb.Timestamp{Seconds: 1, Nanos: 0}, |
| 44 | + CompiledTask: &core.CompiledTask{ |
| 45 | + Template: &core.TaskTemplate{ |
| 46 | + Interface: &core.TypedInterface{ |
| 47 | + Inputs: &core.VariableMap{ |
| 48 | + Variables: variableMap, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + } |
| 55 | + mockClient.OnGetTaskMatch(ctx, mock.Anything).Return(task1, nil) |
| 56 | + parameterMap := map[string]*core.Parameter{ |
| 57 | + "numbers": { |
| 58 | + Var: &core.Variable{ |
| 59 | + Type: &core.LiteralType{ |
| 60 | + Type: &core.LiteralType_CollectionType{ |
| 61 | + CollectionType: &core.LiteralType{ |
| 62 | + Type: &core.LiteralType_Simple{ |
| 63 | + Simple: core.SimpleType_INTEGER, |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }, |
| 69 | + }, |
| 70 | + "numbers_count": { |
| 71 | + Var: &core.Variable{ |
| 72 | + Type: &core.LiteralType{ |
| 73 | + Type: &core.LiteralType_Simple{ |
| 74 | + Simple: core.SimpleType_INTEGER, |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + "run_local_at_count": { |
| 80 | + Var: &core.Variable{ |
| 81 | + Type: &core.LiteralType{ |
| 82 | + Type: &core.LiteralType_Simple{ |
| 83 | + Simple: core.SimpleType_INTEGER, |
| 84 | + }, |
| 85 | + }, |
| 86 | + }, |
| 87 | + Behavior: &core.Parameter_Default{ |
| 88 | + Default: &core.Literal{ |
| 89 | + Value: &core.Literal_Scalar{ |
| 90 | + Scalar: &core.Scalar{ |
| 91 | + Value: &core.Scalar_Primitive{ |
| 92 | + Primitive: &core.Primitive{ |
| 93 | + Value: &core.Primitive_Integer{ |
| 94 | + Integer: 10, |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + }, |
| 102 | + }, |
| 103 | + } |
| 104 | + launchPlan1 := &admin.LaunchPlan{ |
| 105 | + Id: &core.Identifier{ |
| 106 | + Name: "core.advanced.run_merge_sort.merge_sort", |
| 107 | + Version: "v3", |
| 108 | + }, |
| 109 | + Spec: &admin.LaunchPlanSpec{ |
| 110 | + DefaultInputs: &core.ParameterMap{ |
| 111 | + Parameters: parameterMap, |
| 112 | + }, |
| 113 | + }, |
| 114 | + Closure: &admin.LaunchPlanClosure{ |
| 115 | + CreatedAt: ×tamppb.Timestamp{Seconds: 0, Nanos: 0}, |
| 116 | + ExpectedInputs: &core.ParameterMap{ |
| 117 | + Parameters: parameterMap, |
| 118 | + }, |
| 119 | + }, |
| 120 | + } |
| 121 | + objectGetRequest := &admin.ObjectGetRequest{ |
| 122 | + Id: &core.Identifier{ |
| 123 | + ResourceType: core.ResourceType_LAUNCH_PLAN, |
| 124 | + Project: config.GetConfig().Project, |
| 125 | + Domain: config.GetConfig().Domain, |
| 126 | + Name: "core.advanced.run_merge_sort.merge_sort", |
| 127 | + Version: "v3", |
| 128 | + }, |
| 129 | + } |
| 130 | + mockClient.OnGetLaunchPlanMatch(ctx, objectGetRequest).Return(launchPlan1, nil) |
| 131 | +} |
| 132 | +func TestCreateLaunchPlanExecutionFunc(t *testing.T) { |
| 133 | + setup() |
| 134 | + createExecutionSetup() |
| 135 | + executionCreateResponseLP := &admin.ExecutionCreateResponse{ |
| 136 | + Id: &core.WorkflowExecutionIdentifier{ |
| 137 | + Project: "flytesnacks", |
| 138 | + Domain: "development", |
| 139 | + Name: "f652ea3596e7f4d80a0e", |
| 140 | + }, |
| 141 | + } |
| 142 | + mockClient.OnCreateExecutionMatch(ctx, mock.Anything).Return(executionCreateResponseLP, nil) |
| 143 | + executionConfig.ExecFile = testDataFolder + "launchplan_execution_spec.yaml" |
| 144 | + err = createExecutionCommand(ctx, args, cmdCtx) |
| 145 | + assert.Nil(t, err) |
| 146 | + mockClient.AssertCalled(t, "CreateExecution", ctx, mock.Anything) |
| 147 | + tearDownAndVerify(t, `execution identifier project:"flytesnacks" domain:"development" name:"f652ea3596e7f4d80a0e"`) |
| 148 | +} |
| 149 | + |
| 150 | +func TestCreateTaskExecutionFunc(t *testing.T) { |
| 151 | + setup() |
| 152 | + createExecutionSetup() |
| 153 | + executionCreateResponseTask := &admin.ExecutionCreateResponse{ |
| 154 | + Id: &core.WorkflowExecutionIdentifier{ |
| 155 | + Project: "flytesnacks", |
| 156 | + Domain: "development", |
| 157 | + Name: "ff513c0e44b5b4a35aa5", |
| 158 | + }, |
| 159 | + } |
| 160 | + mockClient.OnCreateExecutionMatch(ctx, mock.Anything).Return(executionCreateResponseTask, nil) |
| 161 | + executionConfig.ExecFile = testDataFolder + "task_execution_spec.yaml" |
| 162 | + err = createExecutionCommand(ctx, args, cmdCtx) |
| 163 | + assert.Nil(t, err) |
| 164 | + mockClient.AssertCalled(t, "CreateExecution", ctx, mock.Anything) |
| 165 | + tearDownAndVerify(t, `execution identifier project:"flytesnacks" domain:"development" name:"ff513c0e44b5b4a35aa5" `) |
| 166 | +} |
0 commit comments