github.com/friesencr/pop/v6@v6.1.6/genny/config/config_test.go (about)

     1  package config
     2  
     3  import (
     4  	"context"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/friesencr/pop/v6"
     9  	"github.com/gobuffalo/genny/v2"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func Test_New(t *testing.T) {
    14  	r := require.New(t)
    15  
    16  	for _, d := range pop.AvailableDialects {
    17  		run := genny.DryRunner(context.Background())
    18  
    19  		g, err := New(&Options{
    20  			Prefix:  "foo",
    21  			Dialect: d,
    22  		})
    23  
    24  		r.NoError(err)
    25  		run.With(g)
    26  		r.NoError(run.Run())
    27  
    28  		res := run.Results()
    29  		r.Len(res.Commands, 0)
    30  		r.Len(res.Files, 1)
    31  
    32  		f := res.Files[0]
    33  		r.Equal("database.yml", filepath.Base(f.Name()))
    34  		body := f.String()
    35  		r.Contains(body, d)
    36  		r.Contains(body, "foo_development")
    37  		r.Contains(body, "foo_production")
    38  		r.Contains(body, "foo_test")
    39  	}
    40  }
    41  
    42  func Test_New_No_Dialect(t *testing.T) {
    43  	r := require.New(t)
    44  
    45  	_, err := New(&Options{
    46  		Prefix: "foo",
    47  	})
    48  
    49  	r.Error(err)
    50  }
    51  
    52  func Test_New_No_Prefix(t *testing.T) {
    53  	r := require.New(t)
    54  
    55  	_, err := New(&Options{
    56  		Dialect: "postgres",
    57  	})
    58  
    59  	r.Error(err)
    60  }
    61  
    62  func Test_New_BadDialect(t *testing.T) {
    63  	r := require.New(t)
    64  
    65  	_, err := New(&Options{
    66  		Prefix:  "foo",
    67  		Dialect: "unknown",
    68  	})
    69  
    70  	r.EqualError(err, "unable to find database.yml template for dialect unknown")
    71  }