github.com/JarrahG/buffalocli@v0.0.0-20230801092127-b85bfd5d395a/internal/genny/ci/ci_test.go (about) 1 package ci 2 3 import ( 4 "testing" 5 6 "github.com/gobuffalo/genny/v2/gentest" 7 "github.com/gobuffalo/meta" 8 "github.com/stretchr/testify/require" 9 "gopkg.in/yaml.v2" 10 ) 11 12 func Test_New_Circle(t *testing.T) { 13 r := require.New(t) 14 15 g, err := New(&Options{ 16 Provider: "circleci", 17 DBType: "postgres", 18 }) 19 r.NoError(err) 20 21 run := gentest.NewRunner() 22 r.NoError(run.With(g)) 23 r.NoError(run.Run()) 24 25 res := run.Results() 26 r.Len(res.Commands, 0) 27 r.Len(res.Files, 1) 28 29 f := res.Files[0] 30 r.Equal(".circleci/config.yml", f.Name()) 31 circleYml := struct { 32 Version int 33 }{} 34 r.NoError(yaml.NewDecoder(f).Decode(&circleYml), "config.yml is a valid YAML file") 35 } 36 37 func Test_New_Github(t *testing.T) { 38 r := require.New(t) 39 40 g, err := New(&Options{ 41 Provider: "github", 42 DBType: "postgres", 43 }) 44 r.NoError(err) 45 46 run := gentest.NewRunner() 47 r.NoError(run.With(g)) 48 r.NoError(run.Run()) 49 50 res := run.Results() 51 r.Len(res.Commands, 0) 52 r.Len(res.Files, 1) 53 54 f := res.Files[0] 55 r.Equal(".github/workflows/test.yml", f.Name()) 56 githubYml := struct { 57 Name string 58 }{} 59 r.NoError(yaml.NewDecoder(f).Decode(&githubYml), "test.yml is a valid YAML file") 60 } 61 62 func Test_New_Gitlab(t *testing.T) { 63 r := require.New(t) 64 65 app := meta.New(".") 66 app.WithPop = true 67 68 g, err := New(&Options{ 69 App: app, 70 Provider: "gitlab", 71 DBType: "postgres", 72 }) 73 r.NoError(err) 74 75 run := gentest.NewRunner() 76 r.NoError(run.With(g)) 77 r.NoError(run.Run()) 78 79 res := run.Results() 80 r.Len(res.Commands, 0) 81 r.Len(res.Files, 1) 82 83 f := res.Files[0] 84 r.Equal(".gitlab-ci.yml", f.Name()) 85 r.Contains(f.String(), "postgres:5432") 86 } 87 88 func Test_New_Gitlab_No_pop(t *testing.T) { 89 r := require.New(t) 90 91 g, err := New(&Options{ 92 Provider: "gitlab", 93 DBType: "postgres", 94 }) 95 r.NoError(err) 96 97 run := gentest.NewRunner() 98 r.NoError(run.With(g)) 99 r.NoError(run.Run()) 100 101 res := run.Results() 102 r.Len(res.Commands, 0) 103 r.Len(res.Files, 1) 104 105 f := res.Files[0] 106 r.Equal(".gitlab-ci.yml", f.Name()) 107 r.NotContains(f.String(), "postgres:5432") 108 } 109 110 func Test_New_Travis(t *testing.T) { 111 r := require.New(t) 112 113 g, err := New(&Options{ 114 Provider: "travis", 115 DBType: "postgres", 116 }) 117 r.NoError(err) 118 119 run := gentest.NewRunner() 120 r.NoError(run.With(g)) 121 r.NoError(run.Run()) 122 123 res := run.Results() 124 r.Len(res.Commands, 0) 125 r.Len(res.Files, 1) 126 127 f := res.Files[0] 128 r.Equal(".travis.yml", f.Name()) 129 travisYml := struct { 130 Language string 131 Go []string 132 Env []string 133 Services []string 134 BeforeScript []string `yaml:"before_script"` 135 GoImportPath string `yaml:"go_import_path"` 136 Install []string 137 Script string 138 }{} 139 r.NoError(yaml.NewDecoder(f).Decode(&travisYml), ".travis.yml is a valid YAML file") 140 }