kubesphere.io/s2irun@v3.2.1+incompatible/pkg/build/strategies/dockerfile/dockerfile_test.go (about) 1 package dockerfile 2 3 import ( 4 "testing" 5 6 "github.com/kubesphere/s2irun/pkg/api" 7 ) 8 9 func TestGetImageScriptsDir(t *testing.T) { 10 type testCase struct { 11 Config *api.Config 12 ExpectedDir string 13 HasAllScripts bool 14 } 15 16 cases := []testCase{ 17 { 18 Config: &api.Config{}, 19 ExpectedDir: defaultScriptsDir, 20 }, 21 { 22 Config: &api.Config{ 23 ScriptsURL: "image:///usr/some/dir", 24 }, 25 ExpectedDir: "/usr/some/dir", 26 HasAllScripts: true, 27 }, 28 { 29 Config: &api.Config{ 30 ScriptsURL: "https://github.com/s2iservice", 31 }, 32 ExpectedDir: defaultScriptsDir, 33 }, 34 { 35 Config: &api.Config{ 36 ImageScriptsURL: "image:///usr/some/dir", 37 }, 38 ExpectedDir: "/usr/some/dir", 39 }, 40 { 41 Config: &api.Config{ 42 ImageScriptsURL: "https://github.com/s2iservice", 43 }, 44 ExpectedDir: defaultScriptsDir, 45 }, 46 { 47 Config: &api.Config{ 48 ScriptsURL: "https://github.com/s2iservice", 49 ImageScriptsURL: "image:///usr/some/dir", 50 }, 51 ExpectedDir: "/usr/some/dir", 52 }, 53 { 54 Config: &api.Config{ 55 ScriptsURL: "image:///usr/some/dir", 56 ImageScriptsURL: "image:///usr/other/dir", 57 }, 58 ExpectedDir: "/usr/some/dir", 59 HasAllScripts: true, 60 }, 61 } 62 for _, tc := range cases { 63 output, hasScripts := getImageScriptsDir(tc.Config) 64 if output != tc.ExpectedDir { 65 t.Errorf("Expected image scripts dir %s to be %s", output, tc.ExpectedDir) 66 } 67 if hasScripts != tc.HasAllScripts { 68 t.Errorf("Expected has all scripts indicator:\n%v\nto be: %v", hasScripts, tc.HasAllScripts) 69 } 70 } 71 }