github.com/tagesspiegel/helm-plugin-bootstrap@v0.2.3/internal/bootstrap/package_test.go (about) 1 package bootstrap 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 "os/exec" 8 "path" 9 "testing" 10 "time" 11 ) 12 13 var ( 14 chartName = "test-chart" 15 chartLocation = path.Join(os.TempDir(), "charts") 16 ) 17 18 func TestMain(m *testing.M) { 19 binPath, err := exec.LookPath("helm") 20 if err != nil { 21 fmt.Println("helm not found") 22 os.Exit(1) 23 } 24 err = os.MkdirAll(chartLocation, 0755) 25 if err != nil { 26 fmt.Println("failed to create chart directory") 27 os.Exit(1) 28 } 29 defer os.RemoveAll(chartLocation) 30 31 ctx, cf := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second)) 32 defer cf() 33 34 err = os.Chdir(chartLocation) 35 if err != nil { 36 fmt.Println("failed to create chart directory") 37 os.Exit(1) 38 } 39 40 if err := exec.CommandContext(ctx, binPath, "create", chartName).Run(); err != nil { 41 fmt.Println("failed to create chart", err.Error()) 42 os.Exit(1) 43 } 44 45 if exitCode := m.Run(); exitCode != 0 { 46 os.Exit(exitCode) 47 } 48 }