github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/genny/ci/ci_test.go (about)

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