github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/test/e2e/task-decoration/setup_test.go (about) 1 package taskdecorationtest 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/benchkram/bob/bob" 8 "github.com/benchkram/errz" 9 . "github.com/onsi/gomega" 10 ) 11 12 func BobSetup() (_ *bob.B, err error) { 13 return bobSetup() 14 } 15 16 func bobSetup(opts ...bob.Option) (_ *bob.B, err error) { 17 defer errz.Recover(&err) 18 19 static := []bob.Option{ 20 bob.WithDir(dir), 21 bob.WithFilestore(artifactStore), 22 bob.WithBuildinfoStore(buildInfoStore), 23 } 24 static = append(static, opts...) 25 return bob.Bob( 26 static..., 27 ) 28 } 29 30 // useBobfile sets the right bobfile to be used for test 31 func useBobfile(name string) { 32 err := os.Rename(name+".yaml", "bob.yaml") 33 Expect(err).ToNot(HaveOccurred()) 34 } 35 36 // releaseBobfile will revert changes done in useBobfile 37 func releaseBobfile(name string) { 38 err := os.Rename("bob.yaml", name+".yaml") 39 Expect(err).ToNot(HaveOccurred()) 40 } 41 42 func useSecondLevelBobfile(name string) { 43 err := os.Rename(name+"_"+secondLevelDir+".yaml", filepath.Join(dir, secondLevelDir, "bob.yaml")) 44 Expect(err).ToNot(HaveOccurred()) 45 } 46 47 // releaseBobfile will revert changes done in useSecondLevelBobfile 48 func releaseSecondLevelBobfile(name string) { 49 err := os.Rename( 50 filepath.Join(dir, secondLevelDir, "bob.yaml"), 51 name+"_"+secondLevelDir+".yaml") 52 Expect(err).ToNot(HaveOccurred()) 53 } 54 55 func useThirdLevelBobfile(name string) { 56 err := os.Rename( 57 name+"_"+secondLevelDir+"_"+thirdLevelDir+".yaml", 58 filepath.Join(dir, secondLevelDir, thirdLevelDir, "bob.yaml")) 59 Expect(err).ToNot(HaveOccurred()) 60 } 61 62 // releaseBobfile will revert changes done in useThirdLevelBobfile 63 func releaseThirdLevelBobfile(name string) { 64 err := os.Rename( 65 filepath.Join(dir, secondLevelDir, thirdLevelDir, "bob.yaml"), 66 name+"_"+secondLevelDir+"_"+thirdLevelDir+".yaml") 67 Expect(err).ToNot(HaveOccurred()) 68 }