diff --git a/my-integration/cmd/commands.go b/my-integration/cmd/commands.go index 3146e69..2abde4b 100644 --- a/my-integration/cmd/commands.go +++ b/my-integration/cmd/commands.go @@ -25,3 +25,10 @@ type AbortHello struct { type TestConnectionCommand struct { httpClient *http.HttpClient } + +type HelloWithLookup struct { + YourName string `json:"yourName"` +} + +type LookupNames struct { +} diff --git a/my-integration/cmd/example/hello.go b/my-integration/cmd/example/hello.go index 691c3e3..27acdfd 100644 --- a/my-integration/cmd/example/hello.go +++ b/my-integration/cmd/example/hello.go @@ -20,3 +20,14 @@ func Hello(yourName string) (*task.Result, error) { // Return greeting in the output of the task return task.NewResult().String("greeting", greeting), nil } + +// ListNames lists names as array of lookup result elements +func ListNames() (*task.Result, error) { + lookupResult := []task.LookupResultElement{ + {Label: "World", Value: "World"}, + {Label: "John", Value: "John"}, + {Label: "Bob", Value: "Bob"}, + {Label: "Mary", Value: "Mary"}, + } + return task.NewResult().LookupResultElements(task.DefaultResponseResultField, lookupResult), nil +} diff --git a/my-integration/cmd/example/hello_test.go b/my-integration/cmd/example/hello_test.go index 8336e9a..6f190f4 100644 --- a/my-integration/cmd/example/hello_test.go +++ b/my-integration/cmd/example/hello_test.go @@ -34,3 +34,28 @@ func TestHello(t *testing.T) { }) } } + +func TestListNames(t *testing.T) { + + tests := []struct { + output *task.Result + err error + }{ + { + output: task.NewResult().LookupResultElements(task.DefaultResponseResultField, []task.LookupResultElement{ + {Label: "World", Value: "World"}, + {Label: "John", Value: "John"}, + {Label: "Bob", Value: "Bob"}, + {Label: "Mary", Value: "Mary"}, + }), + err: nil, + }, + } + + for _, testCase := range tests { + t.Run(fmt.Sprintf("ListNames"), func(t *testing.T) { + result, err := ListNames() + test.AssertRequestResult(t, result, err, testCase.output, testCase.err) + }) + } +} diff --git a/my-integration/cmd/executors.go b/my-integration/cmd/executors.go index 2207dde..fa2830a 100644 --- a/my-integration/cmd/executors.go +++ b/my-integration/cmd/executors.go @@ -31,3 +31,11 @@ func (command *TestConnectionCommand) FetchResult(ctx context.Context) (*task.Re } return test.TestConnection(tester) } + +func (command *HelloWithLookup) FetchResult(ctx context.Context) (*task.Result, error) { + return example.Hello(command.YourName) +} + +func (command *LookupNames) FetchResult(ctx context.Context) (*task.Result, error) { + return example.ListNames() +} diff --git a/my-integration/cmd/factory.go b/my-integration/cmd/factory.go index 59a250a..8da40a0 100644 --- a/my-integration/cmd/factory.go +++ b/my-integration/cmd/factory.go @@ -14,6 +14,8 @@ const ( setSystemMessage = "goContainerExamples.SetSystemMessage" serverQuery = "goContainerExamples.ServerQuery" testConnection = "goContainerExamples.TestConnection" + helloWithLookup = "goContainerExamples.HelloWithLookup" + nameLookup = "goContainerExamples.NameLookup" ) type CommandFactory struct { @@ -54,4 +56,8 @@ var commandHatchery = map[command.CommandType]func(*CommandFactory) command.Comm testConnection: func(factory *CommandFactory) command.CommandExecutor { return &TestConnectionCommand{httpClient: factory.httpClient} }, + helloWithLookup: func(factory *CommandFactory) command.CommandExecutor { + return &HelloWithLookup{} + }, + nameLookup: func(factory *CommandFactory) command.CommandExecutor { return &LookupNames{} }, } diff --git a/resources/type-definitions.yaml b/resources/type-definitions.yaml index 68890ec..b07bc85 100644 --- a/resources/type-definitions.yaml +++ b/resources/type-definitions.yaml @@ -112,3 +112,42 @@ types: kind: ci referenced-type: goContainerExamples.Server + # Example lookup task + goContainerExamples.NameLookup: + extends: goContainerExamples.BaseScript + + input-properties: + _ci: + kind: ci + referenced-type: goContainerExamples.BaseTask + required: true + _attributes: + kind: map_string_string + required: true + _parameters: + kind: ci + referenced-type: udm.Parameters + required: true + + # Simple example task which uses lookup + goContainerExamples.HelloWithLookup: + extends: goContainerExamples.BaseTask + label: "Container Examples: Hello with Lookup (Go)" + description: Simple greeter task with lookup + + input-properties: + yourName: + description: The name to greet + kind: string + default: World + input-hint: + method-ref: nameLookup + + methods: + nameLookup: + delegate: remoteScriptLookup + script: goContainerExamples.NameLookup + + output-properties: + greeting: + kind: string