Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

S-104892 Add lookup example scripts to go-template #17

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions my-integration/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ type AbortHello struct {
type TestConnectionCommand struct {
httpClient *http.HttpClient
}

type HelloWithLookup struct {
YourName string `json:"yourName"`
}

type LookupNames struct {
}
11 changes: 11 additions & 0 deletions my-integration/cmd/example/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
25 changes: 25 additions & 0 deletions my-integration/cmd/example/hello_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
8 changes: 8 additions & 0 deletions my-integration/cmd/executors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
6 changes: 6 additions & 0 deletions my-integration/cmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const (
setSystemMessage = "goContainerExamples.SetSystemMessage"
serverQuery = "goContainerExamples.ServerQuery"
testConnection = "goContainerExamples.TestConnection"
helloWithLookup = "goContainerExamples.HelloWithLookup"
nameLookup = "goContainerExamples.NameLookup"
)

type CommandFactory struct {
Expand Down Expand Up @@ -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{} },
}
39 changes: 39 additions & 0 deletions resources/type-definitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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