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

Function validateGroup

pkg/validation/commands.go:81–114  ·  view source on GitHub ↗

validateGroup validates commands belonging to a specific group kind. If there are multiple commands belonging to the same group: 1. without any default, err out 2. with more than one default, err out

(commands []v1alpha2.Command, groupKind v1alpha2.CommandGroupKind)

Source from the content-addressed store, hash-verified

79// 1. without any default, err out
80// 2. with more than one default, err out
81func validateGroup(commands []v1alpha2.Command, groupKind v1alpha2.CommandGroupKind) error {
82 defaultCommandCount := 0
83 var defaultCommands []v1alpha2.Command
84 if len(commands) > 1 {
85 for _, command := range commands {
86 defaultVal := getGroup(command).IsDefault
87 if defaultVal != nil && *defaultVal {
88 defaultCommandCount++
89 defaultCommands = append(defaultCommands, command)
90 }
91 }
92 } else {
93 return nil
94 }
95
96 if defaultCommandCount == 0 {
97 return &MissingDefaultCmdWarning{groupKind: groupKind}
98 } else if defaultCommandCount > 1 {
99 var commandsReferenceList []string
100 for _, command := range defaultCommands {
101 commandsReferenceList = append(commandsReferenceList,
102 resolveErrorMessageWithImportAttributes(fmt.Errorf("command: %s", command.Id), command.Attributes).Error())
103 }
104 commandsReference := strings.Join(commandsReferenceList, "; ")
105 // example: there should be exactly one default command, currently there are multiple commands;
106 // command: <id1>; command: <id2>, imported from uri: http://127.0.0.1:8080, in parent overrides from main devfile"
107 return &MultipleDefaultCmdError{
108 groupKind: groupKind,
109 commandsReference: commandsReference,
110 }
111 }
112
113 return nil
114}
115
116// getGroup returns the group the command belongs to, or nil if the command does not belong to a group
117func getGroup(command v1alpha2.Command) *v1alpha2.CommandGroup {

Callers 2

ValidateCommandsFunction · 0.85
TestValidateGroupFunction · 0.85

Calls 3

getGroupFunction · 0.70
ErrorMethod · 0.45

Tested by 1

TestValidateGroupFunction · 0.68