diff --git a/devfile.yaml b/devfile.yaml index f3c074db..0508b153 100644 --- a/devfile.yaml +++ b/devfile.yaml @@ -28,12 +28,14 @@ components: strategy: Dockerfile container: endpoints: - - name: http-3000 - targetPort: 3000 + - name: http-8888 + targetPort: 8888 image: registry.access.redhat.com/ubi8/nodejs-12:1-45 memoryLimit: 1024Mi mountSources: true sourceMapping: /project + command: + - npm install - name: runtime3 attributes: tool: odo @@ -41,8 +43,8 @@ components: usage: deploy container: endpoints: - - name: http-3000 - targetPort: 3000 + - name: http-8080 + targetPort: 8080 image: registry.access.redhat.com/ubi8/nodejs-12:1-45 memoryLimit: 1024Mi mountSources: true @@ -52,8 +54,8 @@ components: tool: workspace-operator container: endpoints: - - name: http-3000 - targetPort: 3000 + - name: http-9090 + targetPort: 9090 image: registry.access.redhat.com/ubi8/nodejs-12:1-45 memoryLimit: 1024Mi mountSources: true @@ -63,7 +65,7 @@ commands: commandLine: npm install component: runtime2 group: - isDefault: true + isDefault: false kind: build workingDir: /project id: install2 @@ -74,7 +76,7 @@ commands: commandLine: npm start component: runtime2 group: - isDefault: true + isDefault: false kind: run workingDir: /project id: run2 @@ -85,7 +87,7 @@ commands: commandLine: npm run debug component: runtime2 group: - isDefault: true + isDefault: false kind: debug workingDir: /project id: debug2 @@ -93,7 +95,7 @@ commands: commandLine: npm test component: runtime2 group: - isDefault: true + isDefault: false kind: test workingDir: /project id: test2 diff --git a/go.mod b/go.mod index 2be5b7e9..0b91943a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/devfile/library go 1.13 require ( - github.com/devfile/api/v2 v2.0.0-20210121164412-49ba915897f4 + github.com/devfile/api/v2 v2.0.0-20210202172954-6424f4139ac7 github.com/fatih/color v1.7.0 github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/gobwas/glob v0.2.3 diff --git a/go.sum b/go.sum index b6b09b9a..d8ff706f 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/devfile/api/v2 v2.0.0-20210121164412-49ba915897f4 h1:jDzWFpF/BoyaemoPjAzw5SmlX172JsSsh+Frujm5Ww4= -github.com/devfile/api/v2 v2.0.0-20210121164412-49ba915897f4/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg= +github.com/devfile/api/v2 v2.0.0-20210202172954-6424f4139ac7 h1:bQGUVLEGQtVkvS94K4gQbu57Rk/npcZQmgORmCWYNy8= +github.com/devfile/api/v2 v2.0.0-20210202172954-6424f4139ac7/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= diff --git a/pkg/devfile/parse.go b/pkg/devfile/parse.go index b420e42d..cebc9fab 100644 --- a/pkg/devfile/parse.go +++ b/pkg/devfile/parse.go @@ -2,6 +2,7 @@ package devfile import ( "github.com/devfile/library/pkg/devfile/parser" + "github.com/devfile/library/pkg/devfile/validate" ) // ParseFromURLAndValidate func parses the devfile data from the url @@ -16,7 +17,11 @@ func ParseFromURLAndValidate(url string) (d parser.DevfileObj, err error) { return d, err } - // generic validation on devfile content - TODO + // generic validation on devfile content + err = validate.ValidateDevfileData(d.Data) + if err != nil { + return d, err + } return d, err } @@ -31,8 +36,11 @@ func ParseFromDataAndValidate(data []byte) (d parser.DevfileObj, err error) { if err != nil { return d, err } - - // generic validation on devfile content - TODO + // generic validation on devfile content + err = validate.ValidateDevfileData(d.Data) + if err != nil { + return d, err + } return d, err } @@ -49,7 +57,11 @@ func ParseAndValidate(path string) (d parser.DevfileObj, err error) { return d, err } - // generic validation on devfile content - TODO + // generic validation on devfile content + err = validate.ValidateDevfileData(d.Data) + if err != nil { + return d, err + } return d, err } diff --git a/pkg/devfile/validate/validate.go b/pkg/devfile/validate/validate.go index 8768d75d..1e795be2 100644 --- a/pkg/devfile/validate/validate.go +++ b/pkg/devfile/validate/validate.go @@ -1,14 +1,65 @@ package validate import ( - "k8s.io/klog" + "fmt" + "github.com/devfile/api/v2/pkg/validation" + devfileData "github.com/devfile/library/pkg/devfile/parser/data" + "github.com/devfile/library/pkg/devfile/parser/data/v2/common" + "strings" ) // ValidateDevfileData validates whether sections of devfile are compatible -func ValidateDevfileData(data interface{}) error { +func ValidateDevfileData(data devfileData.DevfileData) error { - // Skipped - klog.V(4).Info("No validation present. Skipped for the moment.") - return nil + commands, err := data.GetCommands(common.DevfileOptions{}) + if err != nil { + return err + } + components, err := data.GetComponents(common.DevfileOptions{}) + if err != nil { + return err + } + projects, err := data.GetProjects(common.DevfileOptions{}) + if err != nil { + return err + } + //starterProjects, err := data.GetStarterProjects(common.DevfileOptions{}) + //if err != nil { + // return err + //} + + var errstrings []string + // validate components + err = validation.ValidateComponents(components) + if err != nil { + errstrings = append(errstrings, err.Error()) + } + + // validate commands + err = validation.ValidateCommands(commands, components) + if err != nil { + errstrings = append(errstrings, err.Error()) + } + + err = validation.ValidateEvents(data.GetEvents(), commands) + if err != nil { + errstrings = append(errstrings, err.Error()) + } + + err = validation.ValidateProjects(projects) + if err != nil { + errstrings = append(errstrings, err.Error()) + } + + //err = validation.ValidateStarterProjects(starterProjects) + //if err != nil { + // errstrings = append(errstrings, err.Error()) + //} + + if len(errstrings) > 0 { + return fmt.Errorf(strings.Join(errstrings, "\n")) + } else { + return nil + } } diff --git a/tests/README.md b/tests/README.md index 9f51e59f..6d553830 100644 --- a/tests/README.md +++ b/tests/README.md @@ -51,7 +51,6 @@ Each test in ```parser_v200_verify_test.go``` sets values in a test structure wh CommandTypes []schema.CommandType ComponentTypes []schema.ComponentType FileName string - CreateWithParser bool EditContent bool } @@ -68,7 +67,6 @@ An example test: func Test_MultiCommand(t *testing.T) { testContent := TestContent{} testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType, schema.CompositeCommandType} - testContent.CreateWithParser = true testContent.EditContent = true testContent.FileName = GetDevFileName() runTest(testContent, t) @@ -128,14 +126,14 @@ For example add support for apply command to existing command support: 1. In ```command-test-utils.go``` * add functions: - * ```func setApplyCommandValues(applyCommand *schema.ApplyCommand)``` - * randomly set attribute values in the provided apply command object - * ```func createApplyCommand() *schema.ApplyCommand``` - * creates the apply command object and calls setApplyCommandValues to add attribute values + * ```func (devfile *TestDevfile) setApplyCommandValues(applyCommand *schema.Command)``` + * randomly sets attribute values in the provided apply command object + * ```func (devfile *TestDevfile) createApplyCommand() *schema.ApplyCommand``` + * creates an empty apply command object and adds it to parser and test schema data * follow the implementation of other similar functions. * modify: - * ```func generateCommand(command *schema.Command, genericCommand *GenericCommand)``` - * add logic to call createApplyCommand if commandType indicates such. + * ```func (devfile *TestDevfile) AddCommand(commandType schema.CommandType) schema.Command``` + * add logic to call createApplyCommand if commandType indicates such and call setApplyCommandValues * ```func (devfile *TestDevfile) UpdateCommand(command *schema.Command) error``` * add logic to call setApplyCommandValues if commandType indicates such. 1. In ```parser_v200_verify_test.go``` @@ -156,24 +154,21 @@ Using existing support for commands as an illustration, any new property support * Specific to commands * Commands require support for 5 different command types: * Exec - * Appy (to be implemented) + * Apply (to be implemented) * Composite * VSCodeLaunch (to be implemented) * VSCodeTask (to be implemented) * Each of these command-types have equivalent functions: - * ```func createCommand() *schema.``` + * ```func (devfile *TestDevfile) createCommand() *schema.Command``` * creates the command object and calls ```setCommandValues``` to add attribute values - * for example see: ```func createExecCommand(execCommand *schema.ExecCommand)``` - * ```func setCommandValues(project-sourceProject *schema.)``` + * for example see: ```func (devfile *TestDevfile) createExecCommand() *schema.Command``` + * ```func (devfile *TestDevfile) setCommandValues(command *schema.Command)``` * sets random attributes into the provided object - * for example see: ```func setExecCommandValues(execCommand *schema.ExecCommand)``` + * for example see: ```func (devfile *TestDevfile) setExecCommandValues(ommand *schema.Command)``` * Functions general to all commands - * ```func generateCommand(command *schema.Command, genericCommand *GenericCommand)``` + * ```func addCommand(genericCommand *GenericCommand) schema.Command``` * includes logic to call the ```createCommand``` function for the command-Type of the supplied command object. - * ```func (devfile *TestDevfile) addCommand(commandType schema.CommandType) string``` * main entry point for a test to add a command - * maintains the array of commands in the schema structure - * calls generateCommand() * ```func (devfile *TestDevfile) UpdateCommand(command *schema.Command) error``` * includes logic to call setCommandValues for each commandType. * ```func (devfile TestDevfile) VerifyCommands(parserCommands []schema.Command) error``` @@ -218,10 +213,9 @@ Create, modify and verify an exec command: 1. parser_v200_verify_test.Test_ExecCommand 1. parser-v200-test.runTest 1. command-test-utils.AddCommand - 1. command-test-utils.GenerateCommand - 1. command-test-utils.createExecCommand - 1. command-test-utils.setExecCommandValues - 1. test-utils.CreateDevfile + 1. command-test-utils.createExecCommand + 1. command-test-utils.setExecCommandValues + 1. test-utils.WriteDevfile 1. test-utils.EditCommands 1. command-test-utils.UpdateCommand 1. command-test-utils.setExecCommandValues diff --git a/tests/api/parser_v200_verify_test.go b/tests/api/parser_v200_verify_test.go index 20ec4fa4..b47b5d29 100644 --- a/tests/api/parser_v200_verify_test.go +++ b/tests/api/parser_v200_verify_test.go @@ -22,17 +22,15 @@ const ( // TestContent - structure used by a test to configure the tests to run type TestContent struct { - CommandTypes []schema.CommandType - ComponentTypes []schema.ComponentType - FileName string - CreateWithParser bool - EditContent bool + CommandTypes []schema.CommandType + ComponentTypes []schema.ComponentType + FileName string + EditContent bool } func Test_ExecCommand(t *testing.T) { testContent := TestContent{} testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType} - testContent.CreateWithParser = false testContent.EditContent = false testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -41,27 +39,6 @@ func Test_ExecCommand(t *testing.T) { func Test_ExecCommandEdit(t *testing.T) { testContent := TestContent{} testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType} - testContent.CreateWithParser = false - testContent.EditContent = true - testContent.FileName = utils.GetDevFileName() - runTest(testContent, t) - runMultiThreadTest(testContent, t) -} - -func Test_ExecCommandParserCreate(t *testing.T) { - testContent := TestContent{} - testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType} - testContent.CreateWithParser = true - testContent.EditContent = false - testContent.FileName = utils.GetDevFileName() - runTest(testContent, t) - runMultiThreadTest(testContent, t) -} - -func Test_ExecCommandEditParserCreate(t *testing.T) { - testContent := TestContent{} - testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType} - testContent.CreateWithParser = true testContent.EditContent = true testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -71,7 +48,6 @@ func Test_ExecCommandEditParserCreate(t *testing.T) { func Test_CompositeCommand(t *testing.T) { testContent := TestContent{} testContent.CommandTypes = []schema.CommandType{schema.CompositeCommandType} - testContent.CreateWithParser = false testContent.EditContent = false testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -80,27 +56,6 @@ func Test_CompositeCommand(t *testing.T) { func Test_CompositeCommandEdit(t *testing.T) { testContent := TestContent{} testContent.CommandTypes = []schema.CommandType{schema.CompositeCommandType} - testContent.CreateWithParser = false - testContent.EditContent = true - testContent.FileName = utils.GetDevFileName() - runTest(testContent, t) - runMultiThreadTest(testContent, t) -} - -func Test_CompositeCommandParserCreate(t *testing.T) { - testContent := TestContent{} - testContent.CommandTypes = []schema.CommandType{schema.CompositeCommandType} - testContent.CreateWithParser = true - testContent.EditContent = false - testContent.FileName = utils.GetDevFileName() - runTest(testContent, t) - runMultiThreadTest(testContent, t) -} - -func Test_CompositeCommandEditParserCreate(t *testing.T) { - testContent := TestContent{} - testContent.CommandTypes = []schema.CommandType{schema.CompositeCommandType} - testContent.CreateWithParser = true testContent.EditContent = true testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -109,8 +64,8 @@ func Test_CompositeCommandEditParserCreate(t *testing.T) { func Test_MultiCommand(t *testing.T) { testContent := TestContent{} - testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType, schema.CompositeCommandType} - testContent.CreateWithParser = true + testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType, + schema.CompositeCommandType} testContent.EditContent = true testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -120,7 +75,6 @@ func Test_MultiCommand(t *testing.T) { func Test_ContainerComponent(t *testing.T) { testContent := TestContent{} testContent.ComponentTypes = []schema.ComponentType{schema.ContainerComponentType} - testContent.CreateWithParser = false testContent.EditContent = false testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -130,27 +84,6 @@ func Test_ContainerComponent(t *testing.T) { func Test_ContainerComponentEdit(t *testing.T) { testContent := TestContent{} testContent.ComponentTypes = []schema.ComponentType{schema.ContainerComponentType} - testContent.CreateWithParser = false - testContent.EditContent = true - testContent.FileName = utils.GetDevFileName() - runTest(testContent, t) - runMultiThreadTest(testContent, t) -} - -func Test_ContainerComponentCreateWithParser(t *testing.T) { - testContent := TestContent{} - testContent.ComponentTypes = []schema.ComponentType{schema.ContainerComponentType} - testContent.CreateWithParser = true - testContent.EditContent = false - testContent.FileName = utils.GetDevFileName() - runTest(testContent, t) - runMultiThreadTest(testContent, t) -} - -func Test_ContainerComponentEditCreateWithParser(t *testing.T) { - testContent := TestContent{} - testContent.ComponentTypes = []schema.ComponentType{schema.ContainerComponentType} - testContent.CreateWithParser = true testContent.EditContent = true testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -160,7 +93,6 @@ func Test_ContainerComponentEditCreateWithParser(t *testing.T) { func Test_VolumeComponent(t *testing.T) { testContent := TestContent{} testContent.ComponentTypes = []schema.ComponentType{schema.VolumeComponentType} - testContent.CreateWithParser = false testContent.EditContent = false testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -170,27 +102,6 @@ func Test_VolumeComponent(t *testing.T) { func Test_VolumeComponentEdit(t *testing.T) { testContent := TestContent{} testContent.ComponentTypes = []schema.ComponentType{schema.VolumeComponentType} - testContent.CreateWithParser = false - testContent.EditContent = true - testContent.FileName = utils.GetDevFileName() - runTest(testContent, t) - runMultiThreadTest(testContent, t) -} - -func Test_VolumeComponentCreateWithParser(t *testing.T) { - testContent := TestContent{} - testContent.ComponentTypes = []schema.ComponentType{schema.VolumeComponentType} - testContent.CreateWithParser = true - testContent.EditContent = false - testContent.FileName = utils.GetDevFileName() - runTest(testContent, t) - runMultiThreadTest(testContent, t) -} - -func Test_VolumeComponentEditCreateWithParser(t *testing.T) { - testContent := TestContent{} - testContent.ComponentTypes = []schema.ComponentType{schema.VolumeComponentType} - testContent.CreateWithParser = true testContent.EditContent = true testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -200,7 +111,6 @@ func Test_VolumeComponentEditCreateWithParser(t *testing.T) { func Test_MultiComponent(t *testing.T) { testContent := TestContent{} testContent.ComponentTypes = []schema.ComponentType{schema.ContainerComponentType, schema.VolumeComponentType} - testContent.CreateWithParser = true testContent.EditContent = true testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -211,7 +121,6 @@ func Test_Everything(t *testing.T) { testContent := TestContent{} testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType, schema.CompositeCommandType} testContent.ComponentTypes = []schema.ComponentType{schema.ContainerComponentType, schema.VolumeComponentType} - testContent.CreateWithParser = true testContent.EditContent = true testContent.FileName = utils.GetDevFileName() runTest(testContent, t) @@ -232,8 +141,8 @@ func runMultiThreadTest(testContent TestContent, t *testing.T) { testContent.FileName = utils.AddSuffixToFileName(devfileName, strconv.Itoa(i)) runTest(testContent, t) - utils.LogMessage(fmt.Sprintf("Sleep 2 seconds to allow all threads to complete : %s", devfileName)) - time.Sleep(2 * time.Second) + utils.LogMessage(fmt.Sprintf("Sleep 3 seconds to allow all threads to complete : %s", devfileName)) + time.Sleep(3 * time.Second) utils.LogMessage(fmt.Sprintf("Sleep complete : %s", devfileName)) } @@ -242,7 +151,10 @@ func runMultiThreadTest(testContent TestContent, t *testing.T) { func runTest(testContent TestContent, t *testing.T) { utils.LogMessage(fmt.Sprintf("Start test for %s", testContent.FileName)) - testDevfile := utils.GetDevfile(testContent.FileName) + testDevfile, err := utils.GetDevfile(testContent.FileName) + if err != nil { + t.Fatalf(utils.LogMessage(fmt.Sprintf("Error creating devfile : %v", err))) + } if len(testContent.CommandTypes) > 0 { numCommands := utils.GetRandomNumber(maxCommands) @@ -260,7 +172,7 @@ func runTest(testContent TestContent, t *testing.T) { } } - err := testDevfile.CreateDevfile(testContent.CreateWithParser) + err = testDevfile.WriteDevfile(utils.GetBinaryDecision()) if err != nil { t.Fatalf(utils.LogErrorMessage(fmt.Sprintf("ERROR creating devfile : %s : %v", testContent.FileName, err))) } diff --git a/tests/utils/command_test_utils.go b/tests/utils/command_test_utils.go index 2b3af3c8..8be1ea5e 100644 --- a/tests/utils/command_test_utils.go +++ b/tests/utils/command_test_utils.go @@ -11,6 +11,19 @@ import ( schema "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" ) +// commandAdded adds a new command to the test schema data and to the parser data +func (devfile *TestDevfile) commandAdded(command schema.Command) { + LogInfoMessage(fmt.Sprintf("command added Id: %s", command.Id)) + devfile.SchemaDevFile.Commands = append(devfile.SchemaDevFile.Commands, command) + devfile.ParserData.AddCommands(command) +} + +// commandUpdated updates a command in the parser data +func (devfile *TestDevfile) commandUpdated(command schema.Command) { + LogInfoMessage(fmt.Sprintf("command updated Id: %s", command.Id)) + devfile.ParserData.UpdateCommand(command) +} + // addEnv creates and returns a specifed number of env attributes in a schema structure func addEnv(numEnv int) []schema.EnvVar { commandEnvs := make([]schema.EnvVar, numEnv) @@ -34,79 +47,81 @@ func addAttributes(numAtrributes int) map[string]string { } // addGroup creates and returns a group in a schema structure -func addGroup() *schema.CommandGroup { +func (devfile *TestDevfile) addGroup() *schema.CommandGroup { commandGroup := schema.CommandGroup{} commandGroup.Kind = GetRandomGroupKind() - LogInfoMessage(fmt.Sprintf("group Kind: %s", commandGroup.Kind)) - commandGroup.IsDefault = GetBinaryDecision() + LogInfoMessage(fmt.Sprintf("group Kind: %s, default already set %t", commandGroup.Kind, devfile.GroupDefaults[commandGroup.Kind])) + // Ensure only one and at least one of each type are labelled as default + if !devfile.GroupDefaults[commandGroup.Kind] { + devfile.GroupDefaults[commandGroup.Kind] = true + commandGroup.IsDefault = true + } else { + commandGroup.IsDefault = false + } LogInfoMessage(fmt.Sprintf("group isDefault: %t", commandGroup.IsDefault)) return &commandGroup } -// AddCommand adds a command of the specified type, with random attributes, to the devfile schema -func (devfile *TestDevfile) AddCommand(commandType schema.CommandType) string { - command := generateCommand(commandType) - devfile.SchemaDevFile.Commands = append(devfile.SchemaDevFile.Commands, command) - return command.Id -} - -// generateCommand creates a command of a specified type in a schema structure -func generateCommand(commandType schema.CommandType) schema.Command { - command := schema.Command{} - command.Id = GetRandomUniqueString(8, true) - LogInfoMessage(fmt.Sprintf("command Id: %s", command.Id)) +// AddCommand creates a command of a specified type in a schema structure and pupulates it with random attributes +func (devfile *TestDevfile) AddCommand(commandType schema.CommandType) schema.Command { + var command *schema.Command if commandType == schema.ExecCommandType { - command.Exec = createExecCommand() + command = devfile.createExecCommand() + devfile.setExecCommandValues(command) + // command must be mentioned by a container component + command.Exec.Component = devfile.GetContainerName() } else if commandType == schema.CompositeCommandType { - command.Composite = createCompositeCommand() + command = devfile.createCompositeCommand() + devfile.setCompositeCommandValues(command) } - return command + return *command } // UpdateCommand randomly updates attribute values of a specified command in the devfile schema -func (devfile *TestDevfile) UpdateCommand(parserCommand *schema.Command) error { +func (devfile *TestDevfile) UpdateCommand(commandId string) error { var err error - testCommand, found := getSchemaCommand(devfile.SchemaDevFile.Commands, parserCommand.Id) + testCommand, found := getSchemaCommand(devfile.SchemaDevFile.Commands, commandId) if found { - LogInfoMessage(fmt.Sprintf("Updating command id: %s", parserCommand.Id)) + LogInfoMessage(fmt.Sprintf("Updating command id: %s", commandId)) if testCommand.Exec != nil { - setExecCommandValues(parserCommand.Exec) + devfile.setExecCommandValues(testCommand) } else if testCommand.Composite != nil { - setCompositeCommandValues(parserCommand.Composite) + devfile.setCompositeCommandValues(testCommand) } - devfile.replaceSchemaCommand(*parserCommand) } else { - err = errors.New(LogErrorMessage(fmt.Sprintf("Command not found in test : %s", parserCommand.Id))) + err = errors.New(LogErrorMessage(fmt.Sprintf("Command not found in test : %s", commandId))) } return err } -// createExecCommand creates and returns an exec command in a schema structure -func createExecCommand() *schema.ExecCommand { +// createExecCommand creates and returns an empty exec command in a schema structure +func (devfile *TestDevfile) createExecCommand() *schema.Command { LogInfoMessage("Create an exec command :") - execCommand := schema.ExecCommand{} - setExecCommandValues(&execCommand) - return &execCommand + command := schema.Command{} + command.Id = GetRandomUniqueString(8, true) + LogInfoMessage(fmt.Sprintf("command Id: %s", command.Id)) + command.Exec = &schema.ExecCommand{} + devfile.commandAdded(command) + return &command } // setExecCommandValues randomly sets exec command attribute to random values -func setExecCommandValues(execCommand *schema.ExecCommand) { - - execCommand.Component = GetRandomString(8, false) - LogInfoMessage(fmt.Sprintf("....... component: %s", execCommand.Component)) +func (devfile *TestDevfile) setExecCommandValues(command *schema.Command) { + execCommand := command.Exec execCommand.CommandLine = GetRandomString(4, false) + " " + GetRandomString(4, false) LogInfoMessage(fmt.Sprintf("....... commandLine: %s", execCommand.CommandLine)) - if GetRandomDecision(2, 1) { - execCommand.Group = addGroup() - } else { - execCommand.Group = nil + // If group already leave it to make sure defaults are not deleted or added + if execCommand.Group == nil { + if GetRandomDecision(2, 1) { + execCommand.Group = devfile.addGroup() + } } if GetBinaryDecision() { @@ -131,20 +146,11 @@ func setExecCommandValues(execCommand *schema.ExecCommand) { } else { execCommand.Env = nil } + devfile.commandUpdated(*command) } -// replaceSchemaCommand uses the specified command to replace the command in the schema structure with the same Id. -func (devfile TestDevfile) replaceSchemaCommand(command schema.Command) { - for i := 0; i < len(devfile.SchemaDevFile.Commands); i++ { - if devfile.SchemaDevFile.Commands[i].Id == command.Id { - devfile.SchemaDevFile.Commands[i] = command - break - } - } -} - -// getSchemaCommand get a command from the devfile schema structure +// getSchemaCommand get a specified command from the devfile schema structure func getSchemaCommand(commands []schema.Command, id string) (*schema.Command, bool) { found := false var schemaCommand schema.Command @@ -158,27 +164,36 @@ func getSchemaCommand(commands []schema.Command, id string) (*schema.Command, bo return &schemaCommand, found } -// createCompositeCommand creates a composite command in a schema structure -func createCompositeCommand() *schema.CompositeCommand { +// createCompositeCommand creates an empty composite command in a schema structure +func (devfile *TestDevfile) createCompositeCommand() *schema.Command { LogInfoMessage("Create a composite command :") - compositeCommand := schema.CompositeCommand{} - setCompositeCommandValues(&compositeCommand) - return &compositeCommand + command := schema.Command{} + command.Id = GetRandomUniqueString(8, true) + LogInfoMessage(fmt.Sprintf("command Id: %s", command.Id)) + command.Composite = &schema.CompositeCommand{} + devfile.commandAdded(command) + + return &command } // setCompositeCommandValues randomly sets composite command attribute to random values -func setCompositeCommandValues(compositeCommand *schema.CompositeCommand) { +func (devfile *TestDevfile) setCompositeCommandValues(command *schema.Command) { + + compositeCommand := command.Composite numCommands := GetRandomNumber(3) - compositeCommand.Commands = make([]string, numCommands) for i := 0; i < numCommands; i++ { - compositeCommand.Commands[i] = GetRandomUniqueString(8, false) - LogInfoMessage(fmt.Sprintf("....... command %d of %d : %s", i, numCommands, compositeCommand.Commands[i])) + execCommand := devfile.AddCommand(schema.ExecCommandType) + compositeCommand.Commands = append(compositeCommand.Commands, execCommand.Id) + LogInfoMessage(fmt.Sprintf("....... command %d of %d : %s", i, numCommands, execCommand.Id)) } - if GetRandomDecision(2, 1) { - compositeCommand.Group = addGroup() + // If group already exists - leave it to make sure defaults are not deleted or added + if compositeCommand.Group == nil { + if GetRandomDecision(2, 1) { + compositeCommand.Group = devfile.addGroup() + } } if GetBinaryDecision() { @@ -190,10 +205,12 @@ func setCompositeCommandValues(compositeCommand *schema.CompositeCommand) { compositeCommand.Parallel = true LogInfoMessage(fmt.Sprintf("....... Parallel: %t", compositeCommand.Parallel)) } + + devfile.commandUpdated(*command) } // VerifyCommands verifies commands returned by the parser are the same as those saved in the devfile schema -func (devfile TestDevfile) VerifyCommands(parserCommands []schema.Command) error { +func (devfile *TestDevfile) VerifyCommands(parserCommands []schema.Command) error { LogInfoMessage("Enter VerifyCommands") var errorString []string diff --git a/tests/utils/component_test_utils.go b/tests/utils/component_test_utils.go index 11442060..cfb05cb4 100644 --- a/tests/utils/component_test_utils.go +++ b/tests/utils/component_test_utils.go @@ -11,11 +11,25 @@ import ( "sigs.k8s.io/yaml" ) +// componentAdded adds a new component to the test schema data and to the parser data +func (devfile *TestDevfile) componentAdded(component schema.Component) { + LogInfoMessage(fmt.Sprintf("component added Name: %s", component.Name)) + devfile.SchemaDevFile.Components = append(devfile.SchemaDevFile.Components, component) + devfile.ParserData.AddComponents([]schema.Component{component}) +} + +// componetUpdated updates a component in the parser data +func (devfile *TestDevfile) componentUpdated(component schema.Component) { + LogInfoMessage(fmt.Sprintf("component updated Name: %s", component.Name)) + devfile.ParserData.UpdateComponent(component) +} + // addVolume returns volumeMounts in a schema structure based on a specified number of volumes -func addVolume(numVols int) []schema.VolumeMount { +func (devfile *TestDevfile) addVolume(numVols int) []schema.VolumeMount { commandVols := make([]schema.VolumeMount, numVols) for i := 0; i < numVols; i++ { - commandVols[i].Name = "name-" + GetRandomString(5, true) + volumeComponent := devfile.AddComponent(schema.VolumeComponentType) + commandVols[i].Name = volumeComponent.Name commandVols[i].Path = "/Path_" + GetRandomString(5, false) LogInfoMessage(fmt.Sprintf("....... Add Volume: %s", commandVols[i])) } @@ -37,53 +51,70 @@ func getSchemaComponent(components []schema.Component, name string) (*schema.Com } // AddComponent adds a component of the specified type, with random attributes, to the devfile schema -func (devfile *TestDevfile) AddComponent(componentType schema.ComponentType) string { - component := generateComponent(componentType) - devfile.SchemaDevFile.Components = append(devfile.SchemaDevFile.Components, component) - return component.Name -} - -// generateComponent generates a component in a schema structure of the specified type -func generateComponent(componentType schema.ComponentType) schema.Component { - - component := schema.Component{} - component.Name = GetRandomUniqueString(8, true) - LogInfoMessage(fmt.Sprintf("....... Name: %s", component.Name)) +func (devfile *TestDevfile) AddComponent(componentType schema.ComponentType) schema.Component { + var component schema.Component if componentType == schema.ContainerComponentType { - component.Container = createContainerComponent() + component = devfile.createContainerComponent() + devfile.setContainerComponentValues(&component) } else if componentType == schema.VolumeComponentType { - component.Volume = createVolumeComponent() + component = devfile.createVolumeComponent() + devfile.setVolumeComponentValues(&component) } return component } -// createContainerComponent creates a container component and set its attribute values -func createContainerComponent() *schema.ContainerComponent { +// createContainerComponent creates a container component, ready for attribute setting +func (devfile *TestDevfile) createContainerComponent() schema.Component { LogInfoMessage("Create a container component :") - - containerComponent := schema.ContainerComponent{} - setContainerComponentValues(&containerComponent) - - return &containerComponent + component := schema.Component{} + component.Name = GetRandomUniqueString(8, true) + LogInfoMessage(fmt.Sprintf("....... Name: %s", component.Name)) + component.Container = &schema.ContainerComponent{} + devfile.componentAdded(component) + return component } -// createVolumeComponent creates a volume component and set its attribute values -func createVolumeComponent() *schema.VolumeComponent { +// createVolumeComponent creates a volume component , ready for attribute setting +func (devfile *TestDevfile) createVolumeComponent() schema.Component { LogInfoMessage("Create a volume component :") + component := schema.Component{} + component.Name = GetRandomUniqueString(8, true) + LogInfoMessage(fmt.Sprintf("....... Name: %s", component.Name)) + component.Volume = &schema.VolumeComponent{} + devfile.componentAdded(component) + return component - volumeComponent := schema.VolumeComponent{} - setVolumeComponentValues(&volumeComponent) +} - return &volumeComponent +// GetContainer returns the name of an existing, or newly created, container. +func (devfile *TestDevfile) GetContainerName() string { + + componentName := "" + for _, currentComponent := range devfile.SchemaDevFile.Components { + if currentComponent.Container != nil { + componentName = currentComponent.Name + LogInfoMessage(fmt.Sprintf("return existing container from GetContainerName : %s", componentName)) + break + } + } + if componentName == "" { + component := devfile.createContainerComponent() + componentName = component.Name + LogInfoMessage(fmt.Sprintf("retrun new container from GetContainerName : %s", componentName)) + } + + return componentName } // setContainerComponentValues randomly sets container component attributes to random values -func setContainerComponentValues(containerComponent *schema.ContainerComponent) { +func (devfile *TestDevfile) setContainerComponentValues(component *schema.Component) { + + containerComponent := component.Container containerComponent.Image = GetRandomUniqueString(8+GetRandomNumber(10), false) @@ -130,42 +161,45 @@ func setContainerComponentValues(containerComponent *schema.ContainerComponent) containerComponent.Env = nil } - if GetBinaryDecision() { - containerComponent.VolumeMounts = addVolume(GetRandomNumber(4)) - } else { - containerComponent.VolumeMounts = nil + if len(containerComponent.VolumeMounts) == 0 { + if GetBinaryDecision() { + containerComponent.VolumeMounts = devfile.addVolume(GetRandomNumber(4)) + } } if GetBinaryDecision() { - containerComponent.Endpoints = CreateEndpoints() + containerComponent.Endpoints = devfile.CreateEndpoints() } + devfile.componentUpdated(*component) + } // setVolumeComponentValues randomly sets volume component attributes to random values -func setVolumeComponentValues(volumeComponent *schema.VolumeComponent) { +func (devfile *TestDevfile) setVolumeComponentValues(component *schema.Component) { - if GetRandomDecision(5, 1) { - volumeComponent.Size = strconv.Itoa(4+GetRandomNumber(252)) + "G" - LogInfoMessage(fmt.Sprintf("....... volumeComponent.Size: %s", volumeComponent.Size)) - } + component.Volume.Size = strconv.Itoa(4+GetRandomNumber(252)) + "G" + LogInfoMessage(fmt.Sprintf("....... volumeComponent.Size: %s", component.Volume.Size)) + devfile.componentUpdated(*component) } // UpdateComponent randomly updates the attribute values of a specified component -func (devfile *TestDevfile) UpdateComponent(component *schema.Component) error { +func (devfile *TestDevfile) UpdateComponent(componentName string) error { var errorString []string - testComponent, found := getSchemaComponent(devfile.SchemaDevFile.Components, component.Name) + testComponent, found := getSchemaComponent(devfile.SchemaDevFile.Components, componentName) if found { - LogInfoMessage(fmt.Sprintf("....... Updating component name: %s", component.Name)) - if testComponent.ComponentType == schema.ContainerComponentType { - setContainerComponentValues(component.Container) - } else if testComponent.ComponentType == schema.VolumeComponentType { - setVolumeComponentValues(component.Volume) + LogInfoMessage(fmt.Sprintf("....... Updating component name: %s", componentName)) + if testComponent.Container != nil { + devfile.setContainerComponentValues(testComponent) + } else if testComponent.Volume != nil { + devfile.setVolumeComponentValues(testComponent) + } else { + errorString = append(errorString, LogInfoMessage(fmt.Sprintf("....... Component is not of expected type."))) } } else { - errorString = append(errorString, LogInfoMessage(fmt.Sprintf("....... Component not found in test : %s", component.Name))) + errorString = append(errorString, LogInfoMessage(fmt.Sprintf("....... Component not found in test : %s", componentName))) } var err error if len(errorString) > 0 { @@ -175,7 +209,7 @@ func (devfile *TestDevfile) UpdateComponent(component *schema.Component) error { } // VerifyComponents verifies components returned by the parser are the same as those saved in the devfile schema -func (devfile TestDevfile) VerifyComponents(parserComponents []schema.Component) error { +func (devfile *TestDevfile) VerifyComponents(parserComponents []schema.Component) error { LogInfoMessage("Enter VerifyComponents") var errorString []string diff --git a/tests/utils/endpoint-test-utils.go b/tests/utils/endpoint-test-utils.go index bb5a67ce..02d3f0a8 100644 --- a/tests/utils/endpoint-test-utils.go +++ b/tests/utils/endpoint-test-utils.go @@ -21,20 +21,42 @@ func getRandomProtocol() schema.EndpointProtocol { return Protocols[GetRandomNumber(len(Protocols))-1] } -// CreateEndpoints createa and returns a randon numebr of endpoints in a schema structure -func CreateEndpoints() []schema.Endpoint { +// getUniquePort return a port value not previously used in that same devfile +func (devfile *TestDevfile) getUniquePort() int { + + // max sure a lot of unique ports exist + maxPorts := len(devfile.UsedPorts) + 5000 + + var port int + used := true + for used { + port = GetRandomNumber(maxPorts) + _, used = devfile.UsedPorts[port] + } + devfile.UsedPorts[port] = true + return port +} + +// CreateEndpoints creates and returns a randon number of endpoints in a schema structure +func (devfile *TestDevfile) CreateEndpoints() []schema.Endpoint { numEndpoints := GetRandomNumber(5) endpoints := make([]schema.Endpoint, numEndpoints) + commonPort := devfile.getUniquePort() + for i := 0; i < numEndpoints; i++ { endpoint := schema.Endpoint{} - endpoint.Name = GetRandomString(GetRandomNumber(15)+5, true) + endpoint.Name = GetRandomUniqueString(GetRandomNumber(15)+5, true) LogInfoMessage(fmt.Sprintf(" ....... add endpoint %d name : %s", i, endpoint.Name)) - endpoint.TargetPort = GetRandomNumber(9999) + if GetBinaryDecision() { + endpoint.TargetPort = devfile.getUniquePort() + } else { + endpoint.TargetPort = commonPort + } LogInfoMessage(fmt.Sprintf(" ....... add endpoint %d targetPort: %d", i, endpoint.TargetPort)) if GetBinaryDecision() { diff --git a/tests/utils/test_utils.go b/tests/utils/test_utils.go index 1ea0deeb..d4f4b09a 100644 --- a/tests/utils/test_utils.go +++ b/tests/utils/test_utils.go @@ -122,10 +122,12 @@ func LogInfoMessage(message string) string { // TestDevfile is a structure used to track a test devfile and its contents type TestDevfile struct { - SchemaDevFile schema.Devfile - FileName string - ParsedSchemaObj parser.DevfileObj - SchemaParsed bool + SchemaDevFile schema.Devfile + FileName string + ParserData devfileData.DevfileData + SchemaParsed bool + GroupDefaults map[schema.CommandGroupKind]bool + UsedPorts map[int]bool } var StringCount int = 0 @@ -188,18 +190,30 @@ func GetRandomNumber(max int) int { } // GetDevfile returns a structure used to represent a specific devfile in a test -func GetDevfile(fileName string) TestDevfile { +func GetDevfile(fileName string) (TestDevfile, error) { + + var err error testDevfile := TestDevfile{} testDevfile.SchemaDevFile = schema.Devfile{} testDevfile.FileName = fileName testDevfile.SchemaDevFile.SchemaVersion = "2.0.0" testDevfile.SchemaParsed = false - return testDevfile + testDevfile.GroupDefaults = make(map[schema.CommandGroupKind]bool) + for _, kind := range GroupKinds { + testDevfile.GroupDefaults[kind] = false + } + testDevfile.ParserData, err = devfileData.NewDevfileData(testDevfile.SchemaDevFile.SchemaVersion) + if err != nil { + return testDevfile, err + } + testDevfile.ParserData.SetSchemaVersion(testDevfile.SchemaDevFile.SchemaVersion) + testDevfile.UsedPorts = make(map[int]bool) + return testDevfile, err } -// CreateDevfile create a devifle on disk for use in a test. +// WriteDevfile create a devifle on disk for use in a test. // If useParser is true the parser library is used to generate the file, otherwise "sigs.k8s.io/yaml" is used. -func (devfile *TestDevfile) CreateDevfile(useParser bool) error { +func (devfile *TestDevfile) WriteDevfile(useParser bool) error { var err error fileName := devfile.FileName @@ -209,38 +223,25 @@ func (devfile *TestDevfile) CreateDevfile(useParser bool) error { if useParser { LogInfoMessage(fmt.Sprintf("Use Parser to write devfile %s", fileName)) - newDevfile, createErr := devfileData.NewDevfileData(devfile.SchemaDevFile.SchemaVersion) - if createErr != nil { - err = errors.New(LogErrorMessage(fmt.Sprintf("Creating new devfile : %v", createErr))) - } else { - newDevfile.SetSchemaVersion(devfile.SchemaDevFile.SchemaVersion) - - // add the commands to new devfile - for _, command := range devfile.SchemaDevFile.Commands { - newDevfile.AddCommands(command) - } - // add components to the new devfile - newDevfile.AddComponents(devfile.SchemaDevFile.Components) - ctx := devfileCtx.NewDevfileCtx(fileName) + ctx := devfileCtx.NewDevfileCtx(fileName) - err = ctx.SetAbsPath() + err = ctx.SetAbsPath() + if err != nil { + LogErrorMessage(fmt.Sprintf("Setting devfile path : %v", err)) + } else { + devObj := parser.DevfileObj{ + Ctx: ctx, + Data: devfile.ParserData, + } + err = devObj.WriteYamlDevfile() if err != nil { - LogErrorMessage(fmt.Sprintf("Setting devfile path : %v", err)) + LogErrorMessage(fmt.Sprintf("Writing devfile : %v", err)) } else { - devObj := parser.DevfileObj{ - Ctx: ctx, - Data: newDevfile, - } - err = devObj.WriteYamlDevfile() - if err != nil { - LogErrorMessage(fmt.Sprintf("Writing devfile : %v", err)) - } else { - devfile.SchemaParsed = false - } + devfile.SchemaParsed = false } - } + } else { LogInfoMessage(fmt.Sprintf("Marshall and write devfile %s", devfile.FileName)) c, marshallErr := yaml.Marshal(&(devfile.SchemaDevFile)) @@ -259,23 +260,30 @@ func (devfile *TestDevfile) CreateDevfile(useParser bool) error { return err } -// Use the parser to parse a devfile on disk +// parseSchema uses the parser to parse a devfile on disk func (devfile *TestDevfile) parseSchema() error { var err error if !devfile.SchemaParsed { - LogInfoMessage(fmt.Sprintf("Parse and Validate %s : ", devfile.FileName)) - devfile.ParsedSchemaObj, err = devfilepkg.ParseAndValidate(devfile.FileName) + err = devfile.WriteDevfile(true) if err != nil { - LogErrorMessage(fmt.Sprintf("From ParseAndValidate %v : ", err)) + LogErrorMessage(fmt.Sprintf("From WriteDevfile %v : ", err)) + } else { + LogInfoMessage(fmt.Sprintf("Parse and Validate %s : ", devfile.FileName)) + parsedSchemaObj, parse_err := devfilepkg.ParseAndValidate(devfile.FileName) + if parse_err != nil { + err = parse_err + LogErrorMessage(fmt.Sprintf("From ParseAndValidate %v : ", err)) + } + devfile.SchemaParsed = true + devfile.ParserData = parsedSchemaObj.Data } - devfile.SchemaParsed = true } return err } // Verify verifies the contents of the specified devfile with the expected content -func (devfile TestDevfile) Verify() error { +func (devfile *TestDevfile) Verify() error { LogInfoMessage(fmt.Sprintf("Verify %s : ", devfile.FileName)) @@ -287,7 +295,7 @@ func (devfile TestDevfile) Verify() error { errorString = append(errorString, LogErrorMessage(fmt.Sprintf("parsing schema %s : %v", devfile.FileName, err))) } else { LogInfoMessage(fmt.Sprintf("Get commands %s : ", devfile.FileName)) - commands, _ := devfile.ParsedSchemaObj.Data.GetCommands(common.DevfileOptions{}) + commands, _ := devfile.ParserData.GetCommands(common.DevfileOptions{}) if commands != nil && len(commands) > 0 { err = devfile.VerifyCommands(commands) if err != nil { @@ -298,7 +306,7 @@ func (devfile TestDevfile) Verify() error { } LogInfoMessage(fmt.Sprintf("Get components %s : ", devfile.FileName)) - components, _ := devfile.ParsedSchemaObj.Data.GetComponents(common.DevfileOptions{}) + components, _ := devfile.ParserData.GetComponents(common.DevfileOptions{}) if components != nil && len(components) > 0 { err = devfile.VerifyComponents(components) if err != nil { @@ -317,7 +325,7 @@ func (devfile TestDevfile) Verify() error { } // EditCommands modifies random attributes for each of the commands in the devfile. -func (devfile TestDevfile) EditCommands() error { +func (devfile *TestDevfile) EditCommands() error { LogInfoMessage(fmt.Sprintf("Edit %s : ", devfile.FileName)) @@ -326,25 +334,19 @@ func (devfile TestDevfile) EditCommands() error { LogErrorMessage(fmt.Sprintf("From parser : %v", err)) } else { LogInfoMessage(fmt.Sprintf(" -> Get commands %s : ", devfile.FileName)) - commands, _ := devfile.ParsedSchemaObj.Data.GetCommands(common.DevfileOptions{}) + commands, _ := devfile.ParserData.GetCommands(common.DevfileOptions{}) for _, command := range commands { - err = devfile.UpdateCommand(&command) + err = devfile.UpdateCommand(command.Id) if err != nil { LogErrorMessage(fmt.Sprintf("Updating command : %v", err)) - } else { - LogInfoMessage(fmt.Sprintf("Update command in Parser : %s", command.Id)) - devfile.ParsedSchemaObj.Data.UpdateCommand(command) } } - LogInfoMessage(fmt.Sprintf("Write updated file to yaml : %s", devfile.FileName)) - devfile.ParsedSchemaObj.WriteYamlDevfile() - devfile.SchemaParsed = false } return err } // EditComponents modifies random attributes for each of the components in the devfile. -func (devfile TestDevfile) EditComponents() error { +func (devfile *TestDevfile) EditComponents() error { LogInfoMessage(fmt.Sprintf("Edit %s : ", devfile.FileName)) @@ -353,23 +355,13 @@ func (devfile TestDevfile) EditComponents() error { LogErrorMessage(fmt.Sprintf("From parser : %v", err)) } else { LogInfoMessage(fmt.Sprintf(" -> Get commands %s : ", devfile.FileName)) - components, _ := devfile.ParsedSchemaObj.Data.GetComponents(common.DevfileOptions{}) + components, _ := devfile.ParserData.GetComponents(common.DevfileOptions{}) for _, component := range components { - err = devfile.UpdateComponent(&component) + err = devfile.UpdateComponent(component.Name) if err != nil { LogErrorMessage(fmt.Sprintf("Updating component : %v", err)) - } else { - LogInfoMessage(fmt.Sprintf("Update component in Parser : %s", component.Name)) - devfile.ParsedSchemaObj.Data.UpdateComponent(component) } } - LogInfoMessage(fmt.Sprintf("Write updated file to yaml : %s", devfile.FileName)) - devfile.ParsedSchemaObj.WriteYamlDevfile() - devfile.SchemaParsed = false } return err } - -func getError(message string) (string, error) { - return message, errors.New(message) -}