diff --git a/go.mod b/go.mod index 5452d871..ca4bc8dc 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/google/go-cmp v0.5.5 github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 github.com/hashicorp/go-multierror v1.1.1 + github.com/hashicorp/go-version v1.3.0 github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 github.com/mattn/go-colorable v0.1.2 // indirect github.com/mattn/go-isatty v0.0.12 // indirect diff --git a/go.sum b/go.sum index 8a4a45db..ad6b6e50 100644 --- a/go.sum +++ b/go.sum @@ -231,6 +231,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw= +github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= diff --git a/pkg/devfile/parser/parse.go b/pkg/devfile/parser/parse.go index e9a12aa2..50850236 100644 --- a/pkg/devfile/parser/parse.go +++ b/pkg/devfile/parser/parse.go @@ -22,6 +22,7 @@ import ( v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" apiOverride "github.com/devfile/api/v2/pkg/utils/overriding" "github.com/devfile/api/v2/pkg/validation" + versionpkg "github.com/hashicorp/go-version" "github.com/pkg/errors" ) @@ -192,6 +193,18 @@ func ParseFromData(data []byte) (d DevfileObj, err error) { func parseParentAndPlugin(d DevfileObj, resolveCtx *resolutionContextTree, tool resolverTools) (err error) { flattenedParent := &v1.DevWorkspaceTemplateSpecContent{} + var mainDevfileVersion, parentDevfileVerson, pluginDevfileVerson *versionpkg.Version + var devfileVersion string + if devfileVersion = d.Ctx.GetApiVersion(); devfileVersion == "" { + devfileVersion = d.Data.GetSchemaVersion() + } + + if devfileVersion != "" { + mainDevfileVersion, err = versionpkg.NewVersion(devfileVersion) + if err != nil { + return fmt.Errorf("fail to parse version of the main devfile") + } + } parent := d.Data.GetParent() if parent != nil { if !reflect.DeepEqual(parent, &v1.Parent{}) { @@ -210,7 +223,20 @@ func parseParentAndPlugin(d DevfileObj, resolveCtx *resolutionContextTree, tool if err != nil { return err } + var devfileVersion string + if devfileVersion = parentDevfileObj.Ctx.GetApiVersion(); devfileVersion == "" { + devfileVersion = parentDevfileObj.Data.GetSchemaVersion() + } + if devfileVersion != "" { + parentDevfileVerson, err = versionpkg.NewVersion(devfileVersion) + if err != nil { + return fmt.Errorf("fail to parse version of parent devfile from: %v", resolveImportReference(parent.ImportReference)) + } + if parentDevfileVerson.GreaterThan(mainDevfileVersion) { + return fmt.Errorf("the parent devfile version from %v is greater than the child devfile version from %v", resolveImportReference(parent.ImportReference), resolveImportReference(resolveCtx.importReference)) + } + } parentWorkspaceContent := parentDevfileObj.Data.GetDevfileWorkspaceSpecContent() // add attribute to parent elements err = addSourceAttributesForOverrideAndMerge(parent.ImportReference, parentWorkspaceContent) @@ -258,6 +284,20 @@ func parseParentAndPlugin(d DevfileObj, resolveCtx *resolutionContextTree, tool if err != nil { return err } + var devfileVersion string + if devfileVersion = pluginDevfileObj.Ctx.GetApiVersion(); devfileVersion == "" { + devfileVersion = pluginDevfileObj.Data.GetSchemaVersion() + } + + if devfileVersion != "" { + pluginDevfileVerson, err = versionpkg.NewVersion(devfileVersion) + if err != nil { + return fmt.Errorf("fail to parse version of plugin devfile from: %v", resolveImportReference(component.Plugin.ImportReference)) + } + if pluginDevfileVerson.GreaterThan(mainDevfileVersion) { + return fmt.Errorf("the plugin devfile version from %v is greater than the child devfile version from %v", resolveImportReference(component.Plugin.ImportReference), resolveImportReference(resolveCtx.importReference)) + } + } pluginWorkspaceContent := pluginDevfileObj.Data.GetDevfileWorkspaceSpecContent() // add attribute to plugin elements err = addSourceAttributesForOverrideAndMerge(plugin.ImportReference, pluginWorkspaceContent) diff --git a/pkg/devfile/parser/parse_test.go b/pkg/devfile/parser/parse_test.go index fccc9d8c..a113b463 100644 --- a/pkg/devfile/parser/parse_test.go +++ b/pkg/devfile/parser/parse_test.go @@ -195,6 +195,8 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { newCmpErr := "Some Components do not override any existing element.* They should be defined in the main body, as new elements, not in the overriding section" newProjectErr := "Some Projects do not override any existing element.* They should be defined in the main body, as new elements, not in the overriding section" importCycleErr := "devfile has an cycle in references: main devfile -> .*" + parentDevfileVersionErr := "the parent devfile version from .* is greater than the child devfile version from main devfile" + pluginDevfileVersionErr := "the plugin devfile version from .* is greater than the child devfile version from main devfile" type args struct { devFileObj DevfileObj @@ -216,6 +218,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ Parent: &v1.Parent{ ParentOverrides: v1.ParentOverrides{ @@ -368,6 +373,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { wantDevFile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -540,6 +548,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -604,6 +615,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { wantDevFile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -791,6 +805,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ Parent: &v1.Parent{ ParentOverrides: v1.ParentOverrides{ @@ -857,6 +874,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -910,6 +930,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Components: []v1.Component{ @@ -967,6 +990,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Events: &v1.Events{ @@ -1001,6 +1027,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { wantDevFile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Events: &v1.Events{ @@ -1024,6 +1053,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Projects: []v1.Project{ @@ -1080,6 +1112,40 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { }, wantErr: []string{parentProjectAlreadyDefinedErr}, }, + { + name: "error out if the parent devfile version is greater than main devfile version", + args: args{ + devFileObj: DevfileObj{ + Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), + Data: &v2.DevfileV2{ + Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: "2.0.0", + }, + DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ + DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{}, + }, + }, + }, + }, + }, + parentDevfile: DevfileObj{ + Data: &v2.DevfileV2{ + Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, + DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ + DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{}, + }, + }, + }, + }, + wantDevFile: DevfileObj{ + Data: &v2.DevfileV2{}, + }, + wantErr: []string{parentDevfileVersionErr}, + }, { name: "it should merge the plugin's uri data and add the local devfile's data", args: args{ @@ -1087,6 +1153,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -1197,6 +1266,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { wantDevFile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -1293,6 +1365,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -1462,6 +1537,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { wantDevFile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -1572,6 +1650,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{}, }, }, @@ -1617,6 +1698,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -1670,6 +1754,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Components: []v1.Component{ @@ -1727,6 +1814,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Projects: []v1.Project{ @@ -1790,6 +1880,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Projects: []v1.Project{ @@ -1881,6 +1974,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -1957,6 +2053,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Components: []v1.Component{ @@ -2039,6 +2138,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ Parent: &v1.Parent{ ParentOverrides: v1.ParentOverrides{ @@ -2202,6 +2304,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { wantDevFile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -2298,6 +2403,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Components: []v1.Component{ @@ -2354,7 +2462,11 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { devFileObj: DevfileObj{ Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ - Devfile: v1.Devfile{}, + Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, + }, }, }, }, @@ -2400,6 +2512,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { wantDevFile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Components: []v1.Component{ @@ -2428,6 +2543,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Components: []v1.Component{ @@ -2485,6 +2603,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ Parent: &v1.Parent{ ParentOverrides: v1.ParentOverrides{ @@ -2535,6 +2656,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { wantDevFile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Components: []v1.Component{ @@ -2604,6 +2728,36 @@ func Test_parseParentAndPluginFromURI(t *testing.T) { wantErr: []string{importCycleErr}, testRecursiveReference: true, }, + { + name: "error out if the plugin devfile is greater than main devfile version", + args: args{ + devFileObj: DevfileObj{ + Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath), + Data: &v2.DevfileV2{ + Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: "2.0.0", + }, + }, + }, + }, + }, + pluginDevfile: DevfileObj{ + Data: &v2.DevfileV2{ + Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, + DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{}, + }, + }, + }, + wantDevFile: DevfileObj{ + Data: &v2.DevfileV2{}, + }, + wantErr: []string{pluginDevfileVersionErr}, + testRecursiveReference: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -2995,6 +3149,9 @@ func Test_parseParentFromRegistry(t *testing.T) { div.RootRequired = &isTrue mainDevfileContent := v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ Parent: &v1.Parent{ ImportReference: v1.ImportReference{ @@ -3062,6 +3219,9 @@ func Test_parseParentFromRegistry(t *testing.T) { resolveImportReference(mainDevfileContent.Parent.ImportReference)).PutString(parentOverrideAttribute, "main devfile") wantDevfileContent := v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{ @@ -3156,6 +3316,9 @@ func Test_parseParentFromRegistry(t *testing.T) { mainDevfile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ Parent: &v1.Parent{ ImportReference: v1.ImportReference{ @@ -3196,6 +3359,9 @@ func Test_parseParentFromRegistry(t *testing.T) { wantDevFile: DevfileObj{ Data: &v2.DevfileV2{ Devfile: v1.Devfile{ + DevfileHeader: devfilepkg.DevfileHeader{ + SchemaVersion: schemaVersion, + }, DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ Commands: []v1.Command{