@@ -8,32 +8,13 @@ import (
88 "gotest.tools/v3/assert"
99)
1010
11- func TestBuildPush (t * testing.T ) {
12- tags := []string {
13- "localhost:5000/my-repository:build-push-tag1" ,
14- "localhost:5000/my-repository:build-push-test" ,
15- }
16- labels := map [string ]string {
17- "a" : "a1" ,
18- }
11+ func testBuildPush (t * testing.T , envFile string , tags []string , labels map [string ]string ) {
1912 err := removeImages (tags )
2013 assert .NilError (t , err )
21- defer removeImages (tags )
22-
23- err = setupLocalRegistry ()
24- assert .NilError (t , err )
25- defer removeLocalRegistry ()
26-
27- err = loginLocalRegistry ()
28- assert .NilError (t , err )
2914
30- err = runActionsCommand ("build-push" , "testdata/build_push_tests/build_push.env" )
15+ err = runActionsCommand ("build-push" , envFile )
3116 assert .NilError (t , err )
3217
33- for _ , tag := range tags {
34- assertBuildPushImages (t , tag , tags , labels )
35- }
36-
3718 err = removeImages (tags )
3819 assert .NilError (t , err )
3920
@@ -47,6 +28,47 @@ func TestBuildPush(t *testing.T) {
4728 }
4829}
4930
31+ func TestBuildPush (t * testing.T ) {
32+ err := setupLocalRegistry ()
33+ assert .NilError (t , err )
34+ defer removeLocalRegistry ()
35+
36+ err = ensureLocalRegistryAlive ()
37+ assert .NilError (t , err )
38+
39+ // Build and push base image
40+ baseTags := []string {
41+ "localhost:5000/org/base:build-push-tag1" ,
42+ "localhost:5000/org/base:build-push-test" ,
43+ }
44+ defer removeImages (baseTags )
45+ testBuildPush (
46+ t ,
47+ "testdata/build_push_tests/build_push.env" ,
48+ baseTags ,
49+ map [string ]string {
50+ "a" : "a1" ,
51+ },
52+ )
53+
54+ err = logoutLocalRegistry ()
55+ assert .NilError (t , err )
56+
57+ // Build and push image using base image from local registry
58+ testBuildPush (
59+ t ,
60+ "testdata/build_push_tests/build_push_from_registry.env" ,
61+ []string {
62+ "localhost:5000/org/repo:build-push-reg-tag1" ,
63+ "localhost:5000/org/repo:build-push-reg-test" ,
64+ },
65+ map [string ]string {
66+ "a" : "a1" ,
67+ "b" : "b1" ,
68+ },
69+ )
70+ }
71+
5072func assertBuildPushImages (t * testing.T , image string , expectedTags []string , expectedLabels map [string ]string ) {
5173 inspect , err := inspectImage (image )
5274 assert .NilError (t , err )
@@ -57,3 +79,15 @@ func assertBuildPushImages(t *testing.T, image string, expectedTags []string, ex
5779 assert .DeepEqual (t , expectedTags , repoTags )
5880 assert .DeepEqual (t , expectedLabels , inspect .Config .Labels )
5981}
82+
83+ func ensureLocalRegistryAlive () error {
84+ if err := loginLocalRegistry (); err != nil {
85+ return err
86+ }
87+
88+ return logoutLocalRegistry ()
89+ }
90+
91+ func logoutLocalRegistry () error {
92+ return exec .Command ("docker" , "logout" , "localhost:5000" ).Run ()
93+ }
0 commit comments