github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/yarn/builder_test.go (about) 1 package yarn 2 3 import ( 4 "context" 5 "os" 6 "testing" 7 ) 8 9 // TestBuildCmd attempts to run yarn install if it finds yarn.lock 10 func TestBuildCmd(t *testing.T) { 11 err := os.Chdir(t.TempDir()) 12 if err != nil { 13 t.Error(err) 14 } 15 16 tcases := []struct { 17 commandNil bool 18 failMessage string 19 beforeFn func() 20 }{ 21 { 22 commandNil: false, 23 failMessage: "command should not be nil", 24 beforeFn: func() { 25 err := os.WriteFile("yarn.lock", []byte{}, 0600) 26 if err != nil { 27 t.Error(err) 28 } 29 }, 30 }, 31 32 { 33 commandNil: true, 34 failMessage: "command should be nil", 35 beforeFn: func() {}, 36 }, 37 } 38 39 p := &Plugin{} 40 for _, tcase := range tcases { 41 err := os.Remove("yarn.lock") 42 if err != nil && !os.IsNotExist(err) { 43 t.Error(err) 44 break 45 } 46 47 tcase.beforeFn() 48 49 c := p.buildCmd(context.Background()) 50 cond := tcase.commandNil && c != nil 51 cond = cond || !tcase.commandNil && c == nil 52 53 if cond { 54 t.Error(tcase.failMessage) 55 } 56 } 57 }