github.com/JarrahG/buffalocli@v0.0.0-20230801092127-b85bfd5d395a/internal/cmd/build/build_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package build_test 5 6 import ( 7 "os" 8 "path/filepath" 9 "runtime" 10 "testing" 11 12 "github.com/JarrahG/buffalocli/internal/testhelpers" 13 "github.com/stretchr/testify/require" 14 ) 15 16 func TestBuild(t *testing.T) { 17 r := require.New(t) 18 r.NoError(testhelpers.EnsureBuffaloCMD(t)) 19 20 tt := []struct { 21 name string 22 newargs []string 23 resourceargs []string 24 appname string 25 }{ 26 { 27 name: "nominal", 28 newargs: []string{"new", "nominal", "-f", "--skip-webpack", "--vcs", "none"}, 29 resourceargs: []string{"g", "resource", "phone", "model"}, 30 appname: "nominal", 31 }, 32 { 33 name: "api", 34 newargs: []string{"new", "api", "-f", "--api", "--vcs", "none"}, 35 resourceargs: []string{"g", "resource", "phone", "model"}, 36 appname: "api", 37 }, 38 { 39 name: "sqlite", 40 newargs: []string{"new", "sqlite", "-f", "--skip-webpack", "--db-type=sqlite3", "--vcs", "none"}, 41 resourceargs: []string{"g", "resource", "phone", "model"}, 42 appname: "sqlite", 43 }, 44 { 45 // this test covers too things at once (to save testing time) 46 // 1. originally this test case is for `--skip-pop` 47 // 2. by using "src" as appname, it covers webpack-copy glob issue (pull/119) 48 name: "skipop", 49 newargs: []string{"new", "src", "-f", "--skip-pop", "--vcs", "none"}, 50 resourceargs: []string{"g", "action", "phone", "new"}, 51 appname: "src", 52 }, 53 } 54 55 for _, tc := range tt { 56 t.Run(tc.name, func(t *testing.T) { 57 testhelpers.RunWithinTempFolder(t, func(t *testing.T) { 58 r := require.New(t) 59 out, err := testhelpers.RunBuffaloCMD(t, tc.newargs) 60 t.Log(out) 61 r.NoError(err) 62 63 r.NoError(os.Chdir(tc.appname)) 64 65 // NOTE: I think adding this to here is totally fine since 66 // this is "integration" test. However, the original reason 67 // I added it now is to prevent build failure when there is 68 // no subdir under templates directory (go:embed * */*) 69 out, err = testhelpers.RunBuffaloCMD(t, tc.resourceargs) 70 t.Log(out) 71 r.NoError(err) 72 73 out, err = testhelpers.RunBuffaloCMD(t, []string{"build"}) 74 t.Log(out) 75 r.NoError(err) 76 }) 77 }) 78 } 79 } 80 81 func TestBuildNoAssets(t *testing.T) { 82 if runtime.GOOS == "windows" { 83 t.Skip("Skipping this test on windows temporarily") 84 } 85 86 r := require.New(t) 87 r.NoError(testhelpers.EnsureBuffaloCMD(t)) 88 testhelpers.RunWithinTempFolder(t, func(t *testing.T) { 89 out, err := testhelpers.RunBuffaloCMD(t, []string{"new", "noassets", "-f", "--skip-webpack", "--vcs", "none"}) 90 t.Log(out) 91 r.NoError(err) 92 93 t.Cleanup(func() { 94 os.RemoveAll("noassets") 95 }) 96 97 r.NoError(os.Chdir("noassets")) 98 99 out, err = testhelpers.RunBuffaloCMD(t, []string{"g", "resource", "phone", "model"}) 100 t.Log(out) 101 r.NoError(err) 102 103 out, err = testhelpers.RunBuffaloCMD(t, []string{"build", "--extract-assets"}) 104 t.Log(out) 105 r.NoError(err) 106 107 r.FileExists(filepath.Join("bin", "assets.zip")) 108 }) 109 }