github.com/kubri/kubri@v0.5.1-0.20240317001612-bda2aaef967e/pkg/cmd/build_test.go (about) 1 package cmd_test 2 3 import ( 4 "bytes" 5 "os" 6 "strings" 7 "testing" 8 9 "github.com/kubri/kubri/internal/test" 10 "github.com/kubri/kubri/pkg/cmd" 11 ) 12 13 func TestBuild(t *testing.T) { 14 tests := []struct { 15 desc string 16 args []string 17 path string 18 config string 19 want string 20 err bool 21 }{ 22 { 23 desc: "no config file", 24 args: []string{"build"}, 25 path: "test.yml", 26 want: "Error: no config file found", 27 err: true, 28 }, 29 { 30 desc: "custom config file path", 31 args: []string{"build", "-c", "test.yml"}, 32 path: "test.yml", 33 want: "Error: no integrations configured", 34 err: true, 35 }, 36 { 37 desc: "apk", 38 args: []string{"build"}, 39 path: "kubri.yml", 40 config: "apk: {}", 41 want: "Completed publishing APK packages.", 42 }, 43 { 44 desc: "appinstaller", 45 args: []string{"build"}, 46 path: "kubri.yml", 47 config: "appinstaller: {}", 48 want: "Completed publishing App Installer packages.", 49 }, 50 { 51 desc: "apt", 52 args: []string{"build"}, 53 path: "kubri.yml", 54 config: "apt: {}", 55 want: "Completed publishing APT packages.", 56 }, 57 { 58 desc: "yum", 59 args: []string{"build"}, 60 path: "kubri.yml", 61 config: "yum: {}", 62 want: "Completed publishing YUM packages.", 63 }, 64 { 65 desc: "sparkle", 66 args: []string{"build"}, 67 path: "kubri.yml", 68 config: "sparkle: {}", 69 want: "Completed publishing Sparkle packages.", 70 }, 71 } 72 73 baseConfig := ` 74 source: 75 type: file 76 path: ` + t.TempDir() + ` 77 target: 78 type: file 79 path: ` + t.TempDir() 80 81 for _, tc := range tests { 82 os.Chdir(t.TempDir()) 83 os.WriteFile(tc.path, test.JoinYAML(tc.config, baseConfig), os.ModePerm) 84 85 var out bytes.Buffer 86 err := cmd.Execute("", cmd.WithArgs(tc.args...), cmd.WithStderr(&out), cmd.WithStdout(&out)) 87 if tc.err != (err != nil) || !strings.Contains(out.String(), tc.want) { 88 t.Errorf("%s should return %q:\n%s", tc.desc, tc.want, &out) 89 } 90 } 91 }