Skip to content

Commit f276a01

Browse files
committed
add setdefault test
Signed-off-by: Stephanie <yangcao@redhat.com>
1 parent 6385074 commit f276a01

File tree

5 files changed

+39
-22
lines changed

5 files changed

+39
-22
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/devfile/library
33
go 1.15
44

55
require (
6-
github.com/devfile/api/v2 v2.0.0-20211220170551-ef9f515cc912
6+
github.com/devfile/api/v2 v2.0.0-20211221202911-64979f3d994e
77
github.com/fatih/color v1.7.0
88
github.com/gobwas/glob v0.2.3
99
github.com/golang/mock v1.5.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ
8383
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8484
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8585
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
86-
github.com/devfile/api/v2 v2.0.0-20211220170551-ef9f515cc912 h1:jduGMsa/0iVZUpEpGI1uY4NNShRa39buaDTx45aiEQ4=
87-
github.com/devfile/api/v2 v2.0.0-20211220170551-ef9f515cc912/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
86+
github.com/devfile/api/v2 v2.0.0-20211221202911-64979f3d994e h1:+wtI5Pq9i58h1xUtQZxFV0Um1Y3l3euck6nhdXO6zik=
87+
github.com/devfile/api/v2 v2.0.0-20211221202911-64979f3d994e/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
8888
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
8989
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
9090
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=

pkg/devfile/parser/parse.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,16 @@ func setDefaults(d DevfileObj) (err error) {
549549

550550
} else if component.Kubernetes != nil {
551551
endpoints = component.Kubernetes.Endpoints
552-
552+
if devfileVersion != string(data.APISchemaVersion200) && devfileVersion != string(data.APISchemaVersion210) {
553+
val := component.Kubernetes.GetDeployByDefault()
554+
component.Kubernetes.DeployByDefault = &val
555+
}
553556
} else if component.Openshift != nil {
554-
555557
endpoints = component.Openshift.Endpoints
558+
if devfileVersion != string(data.APISchemaVersion200) && devfileVersion != string(data.APISchemaVersion210) {
559+
val := component.Openshift.GetDeployByDefault()
560+
component.Openshift.DeployByDefault = &val
561+
}
556562

557563
} else if component.Volume != nil && devfileVersion != string(data.APISchemaVersion200) {
558564
volume := component.Volume
@@ -565,6 +571,8 @@ func setDefaults(d DevfileObj) (err error) {
565571
val := dockerImage.GetRootRequired()
566572
dockerImage.RootRequired = &val
567573
}
574+
val := component.Image.GetAutoBuild()
575+
component.Image.AutoBuild = &val
568576
}
569577

570578
if endpoints != nil {

pkg/devfile/parser/parse_test.go

+24-16
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
160160
},
161161
},
162162
},
163-
testingutil.GetDockerImageTestComponent(divRRTrue, nil),
163+
testingutil.GetDockerImageTestComponent(divRRTrue, nil, nil),
164164
},
165165
Events: &v1.Events{
166166
DevWorkspaceEvents: v1.DevWorkspaceEvents{
@@ -498,7 +498,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
498498
},
499499
},
500500
},
501-
testingutil.GetDockerImageTestComponent(divRRFalse, parentOverridesFromMainDevfile),
501+
testingutil.GetDockerImageTestComponent(divRRFalse, nil, parentOverridesFromMainDevfile),
502502
{
503503
Name: "runtime",
504504
ComponentUnion: v1.ComponentUnion{
@@ -736,7 +736,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
736736
},
737737
},
738738
//no overrides so expected values are the same as the parent
739-
testingutil.GetDockerImageTestComponent(divRRTrue, importFromUri1),
739+
testingutil.GetDockerImageTestComponent(divRRTrue, nil, importFromUri1),
740740
{
741741
Name: "runtime",
742742
ComponentUnion: v1.ComponentUnion{
@@ -1462,7 +1462,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
14621462
},
14631463
},
14641464
},
1465-
testingutil.GetDockerImageTestComponent(divRRFalse, nil),
1465+
testingutil.GetDockerImageTestComponent(divRRFalse, nil, nil),
14661466
},
14671467
Events: &v1.Events{
14681468
DevWorkspaceEvents: v1.DevWorkspaceEvents{
@@ -1600,7 +1600,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
16001600
},
16011601
},
16021602
},
1603-
testingutil.GetDockerImageTestComponent(divRRTrue, pluginOverridesFromMainDevfile),
1603+
testingutil.GetDockerImageTestComponent(divRRTrue, nil, pluginOverridesFromMainDevfile),
16041604
{
16051605
Name: "runtime",
16061606
ComponentUnion: v1.ComponentUnion{
@@ -3107,7 +3107,7 @@ func Test_parseParentFromRegistry(t *testing.T) {
31073107
},
31083108
},
31093109
},
3110-
testingutil.GetDockerImageTestComponent(defaultDiv, nil),
3110+
testingutil.GetDockerImageTestComponent(defaultDiv, nil, nil),
31113111
},
31123112
},
31133113
},
@@ -3249,7 +3249,7 @@ func Test_parseParentFromRegistry(t *testing.T) {
32493249
},
32503250
},
32513251
},
3252-
testingutil.GetDockerImageTestComponent(div, parentOverridesFromMainDevfile),
3252+
testingutil.GetDockerImageTestComponent(div, nil, parentOverridesFromMainDevfile),
32533253
{
32543254
Name: "runtime2",
32553255
ComponentUnion: v1.ComponentUnion{
@@ -3389,7 +3389,7 @@ func Test_parseParentFromRegistry(t *testing.T) {
33893389
},
33903390
},
33913391
},
3392-
testingutil.GetDockerImageTestComponent(defaultDiv, importFromRegistry),
3392+
testingutil.GetDockerImageTestComponent(defaultDiv, nil, importFromRegistry),
33933393
{
33943394
Name: "runtime2",
33953395
ComponentUnion: v1.ComponentUnion{
@@ -3503,7 +3503,7 @@ func Test_parseParentFromKubeCRD(t *testing.T) {
35033503
},
35043504
},
35053505
},
3506-
testingutil.GetDockerImageTestComponent(defaultDiv, nil),
3506+
testingutil.GetDockerImageTestComponent(defaultDiv, nil, nil),
35073507
},
35083508
},
35093509
}
@@ -3522,7 +3522,7 @@ func Test_parseParentFromKubeCRD(t *testing.T) {
35223522
},
35233523
},
35243524
},
3525-
testingutil.GetDockerImageTestComponent(defaultDiv, nil),
3525+
testingutil.GetDockerImageTestComponent(defaultDiv, nil, nil),
35263526
},
35273527
},
35283528
}
@@ -3626,7 +3626,7 @@ func Test_parseParentFromKubeCRD(t *testing.T) {
36263626
},
36273627
},
36283628
},
3629-
testingutil.GetDockerImageTestComponent(div, parentOverridesFromMainDevfile),
3629+
testingutil.GetDockerImageTestComponent(div, nil, parentOverridesFromMainDevfile),
36303630
{
36313631
Name: "runtime",
36323632
ComponentUnion: v1.ComponentUnion{
@@ -3719,7 +3719,7 @@ func Test_parseParentFromKubeCRD(t *testing.T) {
37193719
},
37203720
},
37213721
},
3722-
testingutil.GetDockerImageTestComponent(defaultDiv, importFromKubeCRD),
3722+
testingutil.GetDockerImageTestComponent(defaultDiv, nil, importFromKubeCRD),
37233723
{
37243724
Name: "runtime",
37253725
ComponentUnion: v1.ComponentUnion{
@@ -4490,7 +4490,7 @@ func getUnsetBooleanDevfileTestData(apiVersion string) (devfileData data.Devfile
44904490
}
44914491

44924492
if apiVersion != string(data.APISchemaVersion200) && apiVersion != string(data.APISchemaVersion210) {
4493-
comp := []v1.Component{testingutil.GetDockerImageTestComponent(testingutil.DockerImageValues{}, nil)}
4493+
comp := []v1.Component{testingutil.GetDockerImageTestComponent(testingutil.DockerImageValues{}, nil, nil)}
44944494
err = devfileData.AddComponents(comp)
44954495
}
44964496

@@ -4510,12 +4510,14 @@ func getBooleanDevfileTestData(apiVersion string, setDefault bool) (devfileData
45104510
isDefault *bool
45114511
rootRequired *bool
45124512
ephemeral *bool
4513+
autoBuild *bool
4514+
deployByDefaul *bool
45134515
}
45144516

45154517
//default values according to spec
4516-
defaultBools := boolValues{&isFalse, &isFalse, &isFalse, &isFalse, &isTrue, &isFalse, &isFalse, &isFalse}
4518+
defaultBools := boolValues{&isFalse, &isFalse, &isFalse, &isFalse, &isTrue, &isFalse, &isFalse, &isFalse, &isFalse, &isFalse}
45174519
//set values will be a mix of default and inverse values
4518-
setBools := boolValues{&isTrue, &isTrue, &isFalse, &isTrue, &isFalse, &isFalse, &isTrue, &isFalse}
4520+
setBools := boolValues{&isTrue, &isTrue, &isFalse, &isTrue, &isFalse, &isFalse, &isTrue, &isFalse, &isTrue, &isFalse}
45194521

45204522
var values boolValues
45214523

@@ -4644,8 +4646,14 @@ func getBooleanDevfileTestData(apiVersion string, setDefault bool) (devfileData
46444646
}
46454647

46464648
if apiVersion != string(data.APISchemaVersion200) && apiVersion != string(data.APISchemaVersion210) {
4647-
comp := []v1.Component{testingutil.GetDockerImageTestComponent(testingutil.DockerImageValues{RootRequired: values.rootRequired}, nil)}
4649+
comp := []v1.Component{testingutil.GetDockerImageTestComponent(testingutil.DockerImageValues{RootRequired: values.rootRequired}, values.autoBuild, nil)}
46484650
err = devfileData.AddComponents(comp)
4651+
4652+
openshiftComponent, _ := devfileData.GetComponents(common.DevfileOptions{ComponentOptions: common.ComponentOptions{
4653+
ComponentType: v1.OpenshiftComponentType,
4654+
}})
4655+
openshiftComponent[0].Openshift.DeployByDefault = values.deployByDefaul
4656+
46494657
}
46504658

46514659
return devfileData, err

pkg/testingutil/devfile.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,15 @@ type DockerImageValues struct {
126126

127127
//GetDockerImageTestComponent returns a docker image component that is used for testing.
128128
//The parameters allow customization of the content. If they are set to nil, then the properties will not be set
129-
func GetDockerImageTestComponent(div DockerImageValues, attr attributes.Attributes) v1.Component {
129+
func GetDockerImageTestComponent(div DockerImageValues, autobuild *bool, attr attributes.Attributes) v1.Component {
130130
comp := v1.Component{
131131
Name: "image",
132132
ComponentUnion: v1.ComponentUnion{
133133
Image: &v1.ImageComponent{
134134
Image: v1.Image{
135135
ImageName: div.ImageName,
136136
ImageUnion: v1.ImageUnion{
137+
AutoBuild: autobuild,
137138
Dockerfile: &v1.DockerfileImage{
138139
DockerfileSrc: v1.DockerfileSrc{
139140
Uri: div.Uri,

0 commit comments

Comments
 (0)