MCPcopy Create free account
hub / github.com/devfile/api / TestValidateCommands

Function TestValidateCommands

pkg/validation/commands_test.go:86–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestValidateCommands(t *testing.T) {
87
88 component := "alias1"
89
90 components := []v1alpha2.Component{
91 generateDummyContainerComponent(component, nil, nil, nil, v1alpha2.Annotation{}, false),
92 }
93
94 duplicateKeyErr := "duplicate key: somecommand1"
95 noDefaultCmdErr := ".*there should be exactly one default command, currently there is no default command"
96 multipleDefaultCmdErr := ".*there should be exactly one default command, currently there are multiple default commands"
97 invalidCmdErr := ".*command does not map to a valid component"
98 nonExistCmdInComposite := "the command .* mentioned in the composite command does not exist in the devfile"
99
100 parentOverridesFromMainDevfile := attributes.Attributes{}.PutString(ImportSourceAttribute,
101 "uri: http://127.0.0.1:8080").PutString(ParentOverrideAttribute, "main devfile")
102 invalidCmdErrWithImportAttributes := ".*command does not map to a valid component, imported from uri: http://127.0.0.1:8080, in parent overrides from main devfile"
103
104 tests := []struct {
105 name string
106 commands []v1alpha2.Command
107 wantErr []string
108 }{
109 {
110 name: "Valid Exec Command",
111 commands: []v1alpha2.Command{
112 generateDummyExecCommand("command", component, &v1alpha2.CommandGroup{Kind: runGroup}),
113 },
114 },
115 {
116 name: "Valid Composite Command",
117 commands: []v1alpha2.Command{
118 generateDummyExecCommand("somecommand1", component, nil),
119 generateDummyExecCommand("somecommand2", component, nil),
120 generateDummyCompositeCommand("composite1", []string{"somecommand1", "somecommand2"}, &v1alpha2.CommandGroup{Kind: buildGroup, IsDefault: &isTrue}),
121 },
122 },
123 {
124 name: "Duplicate commands",
125 commands: []v1alpha2.Command{
126 generateDummyExecCommand("somecommand1", component, nil),
127 generateDummyExecCommand("somecommand1", component, nil),
128 },
129 wantErr: []string{duplicateKeyErr},
130 },
131 {
132 name: "Multiple errors: Duplicate commands, non-exist command in composite command",
133 commands: []v1alpha2.Command{
134 generateDummyExecCommand("somecommand1", component, nil),
135 generateDummyCompositeCommand("somecommand1", []string{"fakecommand"}, &v1alpha2.CommandGroup{Kind: buildGroup, IsDefault: &isTrue}),
136 },
137 wantErr: []string{duplicateKeyErr, nonExistCmdInComposite},
138 },
139 {
140 name: "Different command types belonging to the same group but no default",
141 commands: []v1alpha2.Command{
142 generateDummyExecCommand("somecommand1", component, &v1alpha2.CommandGroup{Kind: buildGroup}),
143 generateDummyCompositeCommand("somecommand2", []string{"somecommand1"}, &v1alpha2.CommandGroup{Kind: buildGroup}),

Callers

nothing calls this directly

Calls 7

generateDummyExecCommandFunction · 0.85
ValidateCommandsFunction · 0.85
PutStringMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected