github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/test/e2e/target-cleanup/setup_test.go (about) 1 package targetcleanuptest 2 3 import ( 4 "os" 5 6 "github.com/benchkram/bob/bob" 7 "github.com/benchkram/errz" 8 ) 9 10 func BobSetup() (_ *bob.B, err error) { 11 return bobSetup() 12 } 13 14 func BobSetupNoCache() (_ *bob.B, err error) { 15 return bobSetup(bob.WithCachingEnabled(false)) 16 } 17 18 func bobSetup(opts ...bob.Option) (_ *bob.B, err error) { 19 defer errz.Recover(&err) 20 21 static := []bob.Option{ 22 bob.WithDir(dir), 23 bob.WithFilestore(artifactStore), 24 bob.WithBuildinfoStore(buildInfoStore), 25 } 26 static = append(static, opts...) 27 return bob.Bob( 28 static..., 29 ) 30 } 31 32 // useBobfile sets the right bobfile to be used for test 33 func useBobfile(name string) error { 34 return os.Rename(name+".yaml", "bob.yaml") 35 } 36 37 // releaseBobfile will revert changes done in useBobfile 38 func releaseBobfile(name string) error { 39 return os.Rename("bob.yaml", name+".yaml") 40 } 41 42 // readDir returns the dir entries as string array 43 func readDir(dir string) ([]string, error) { 44 entries, err := os.ReadDir(dir) 45 if err != nil { 46 return []string{}, err 47 } 48 49 var contents []string 50 for _, e := range entries { 51 contents = append(contents, e.Name()) 52 } 53 return contents, nil 54 }