@@ -24,18 +24,18 @@ func TestMetadata(t *testing.T) {
2424}
2525
2626func testCacheOpts (t * testing.T , when spec.G , it spec.S ) {
27- when ("cache options are passed" , func () {
28- it ("image cache format with complete options" , func () {
27+ when ("image cache format options are passed" , func () {
28+ it ("with complete options" , func () {
2929 testcases := []CacheOptTestCase {
3030 {
3131 name : "Build cache as Image" ,
3232 input : "type=build;format=image;name=io.test.io/myorg/my-cache:build" ,
33- output : "type=build;format=image;name=io.test.io/myorg/my-cache:build" ,
33+ output : "type=build;format=image;name=io.test.io/myorg/my-cache:build;type=launch;format=volume;name=; " ,
3434 },
3535 {
3636 name : "Launch cache as Image" ,
3737 input : "type=launch;format=image;name=io.test.io/myorg/my-cache:build" ,
38- output : "type=launch;format=image;name=io.test.io/myorg/my-cache:build" ,
38+ output : "type=build;format=volume;name=;type= launch;format=image;name=io.test.io/myorg/my-cache:build; " ,
3939 },
4040 }
4141
@@ -48,22 +48,17 @@ func testCacheOpts(t *testing.T, when spec.G, it spec.S) {
4848 }
4949 })
5050
51- it ("image cache format with missing options" , func () {
51+ it ("with missing options" , func () {
5252 successTestCases := []CacheOptTestCase {
5353 {
5454 name : "Build cache as Image missing: type" ,
5555 input : "format=image;name=io.test.io/myorg/my-cache:build" ,
56- output : "type=build;format=image;name=io.test.io/myorg/my-cache:build" ,
56+ output : "type=build;format=image;name=io.test.io/myorg/my-cache:build;type=launch;format=volume;name=; " ,
5757 },
5858 {
5959 name : "Build cache as Image missing: format" ,
6060 input : "type=build;name=io.test.io/myorg/my-cache:build" ,
61- output : "type=build;format=volume;name=io.test.io/myorg/my-cache:build" ,
62- },
63- {
64- name : "Build cache as Image missing: type, format" ,
65- input : "name=io.test.io/myorg/my-cache:build" ,
66- output : "type=build;format=volume;name=io.test.io/myorg/my-cache:build" ,
61+ output : "type=build;format=volume;name=io.test.io/myorg/my-cache:build;type=launch;format=volume;name=;" ,
6762 },
6863 {
6964 name : "Build cache as Image missing: name" ,
@@ -72,10 +67,14 @@ func testCacheOpts(t *testing.T, when spec.G, it spec.S) {
7267 shouldFail : true ,
7368 },
7469 {
75- name : "Build cache as Image missing: format, name" ,
76- input : "type=build" ,
77- output : "cache 'name' is required" ,
78- shouldFail : true ,
70+ name : "Build cache as Image missing: type, format" ,
71+ input : "name=io.test.io/myorg/my-cache:build" ,
72+ output : "type=build;format=volume;name=io.test.io/myorg/my-cache:build;type=launch;format=volume;name=;" ,
73+ },
74+ {
75+ name : "Build cache as Image missing: format, name" ,
76+ input : "type=build" ,
77+ output : "type=build;format=volume;name=;type=launch;format=volume;name=;" ,
7978 },
8079 {
8180 name : "Build cache as Image missing: type, name" ,
@@ -94,6 +93,9 @@ func testCacheOpts(t *testing.T, when spec.G, it spec.S) {
9493 for _ , testcase := range successTestCases {
9594 var cacheFlags CacheOpts
9695 t .Logf ("Testing cache type: %s" , testcase .name )
96+ if testcase .name == "Everything missing" {
97+ print ("i am here" )
98+ }
9799 err := cacheFlags .Set (testcase .input )
98100
99101 if testcase .shouldFail {
@@ -106,7 +108,7 @@ func testCacheOpts(t *testing.T, when spec.G, it spec.S) {
106108 }
107109 })
108110
109- it ("image cache format with invalid options" , func () {
111+ it ("with invalid options" , func () {
110112 testcases := []CacheOptTestCase {
111113 {
112114 name : "Invalid cache type" ,
@@ -142,4 +144,68 @@ func testCacheOpts(t *testing.T, when spec.G, it spec.S) {
142144 }
143145 })
144146 })
147+
148+ when ("volume cache format options are passed" , func () {
149+ it ("with complete options" , func () {
150+ testcases := []CacheOptTestCase {
151+ {
152+ name : "Build cache as Volume" ,
153+ input : "type=build;format=volume;name=test-build-volume-cache" ,
154+ output : "type=build;format=volume;name=test-build-volume-cache;type=launch;format=volume;name=;" ,
155+ },
156+ {
157+ name : "Launch cache as Volume" ,
158+ input : "type=launch;format=volume;name=test-launch-volume-cache" ,
159+ output : "type=build;format=volume;name=;type=launch;format=volume;name=test-launch-volume-cache;" ,
160+ },
161+ }
162+
163+ for _ , testcase := range testcases {
164+ var cacheFlags CacheOpts
165+ t .Logf ("Testing cache type: %s" , testcase .name )
166+ err := cacheFlags .Set (testcase .input )
167+ h .AssertNil (t , err )
168+ h .AssertEq (t , testcase .output , cacheFlags .String ())
169+ }
170+ })
171+
172+ it ("with missing options" , func () {
173+ successTestCases := []CacheOptTestCase {
174+ {
175+ name : "Launch cache as Volume missing: format" ,
176+ input : "type=launch;name=test-launch-volume" ,
177+ output : "type=build;format=volume;name=;type=launch;format=volume;name=test-launch-volume;" ,
178+ },
179+ {
180+ name : "Launch cache as Volume missing: name" ,
181+ input : "type=launch;format=volume" ,
182+ output : "type=build;format=volume;name=;type=launch;format=volume;name=;" ,
183+ },
184+ {
185+ name : "Launch cache as Volume missing: format, name" ,
186+ input : "type=launch" ,
187+ output : "type=build;format=volume;name=;type=launch;format=volume;name=;" ,
188+ },
189+ {
190+ name : "Launch cache as Volume missing: type, name" ,
191+ input : "format=volume" ,
192+ output : "type=build;format=volume;name=;type=launch;format=volume;name=;" ,
193+ },
194+ }
195+
196+ for _ , testcase := range successTestCases {
197+ var cacheFlags CacheOpts
198+ t .Logf ("Testing cache type: %s" , testcase .name )
199+ err := cacheFlags .Set (testcase .input )
200+
201+ if testcase .shouldFail {
202+ h .AssertError (t , err , testcase .output )
203+ } else {
204+ h .AssertNil (t , err )
205+ output := cacheFlags .String ()
206+ h .AssertEq (t , testcase .output , output )
207+ }
208+ }
209+ })
210+ })
145211}
0 commit comments