github.com/craigmonson/colonize@v0.1.1-alpha.0.20170808202020-04bf903fb1ea/initialize/init_test.go (about)

     1  package initialize_test
     2  
     3  import (
     4  	. "github.com/craigmonson/colonize/initialize"
     5  
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  
     9  	"io/ioutil"
    10  	"os"
    11  	"reflect"
    12  
    13  	"github.com/craigmonson/colonize/config"
    14  	"github.com/craigmonson/colonize/log_mock"
    15  )
    16  
    17  var test_dir string
    18  var cwd string
    19  var err error
    20  var cfg config.Config
    21  
    22  var _ = BeforeSuite(func() {
    23  
    24  	cwd, err = os.Getwd()
    25  	if err != nil {
    26  		panic(err.Error())
    27  	}
    28  
    29  	test_dir, err = ioutil.TempDir("", "branch_test")
    30  	if err != nil {
    31  		panic(err.Error())
    32  	}
    33  
    34  	err = os.Chdir(test_dir)
    35  	if err != nil {
    36  		panic(err.Error())
    37  	}
    38  
    39  	cfg = config.Config{
    40  		RootPath:   test_dir,
    41  		TmplPath:   test_dir,
    42  		ConfigFile: config.ConfigFile{},
    43  	}
    44  
    45  	Run(&cfg, &log_mock.MockLog{}, RunArgs{
    46  		AcceptDefaults:   true,
    47  		InitEnvironments: "dev,prod",
    48  	})
    49  })
    50  
    51  var _ = AfterSuite(func() {
    52  	os.Chdir(cwd)
    53  	os.RemoveAll(test_dir)
    54  })
    55  
    56  var _ = Describe("init", func() {
    57  
    58  	It("should not raise an error", func() {
    59  		Ω(err).ToNot(HaveOccurred())
    60  	})
    61  
    62  	It("should setup config data w/ defaults", func() {
    63  		defaults := reflect.ValueOf(&config.ConfigFileDefaults).Elem()
    64  		actuals := reflect.ValueOf(&cfg.ConfigFile).Elem()
    65  
    66  		for i := 0; i < defaults.NumField(); i++ {
    67  			Ω(actuals.Field(i).String()).To(Equal(defaults.Field(i).String()))
    68  		}
    69  
    70  	})
    71  
    72  	It("should have created a .colonize.yaml", func() {
    73  		_, err := os.Stat(".colonize.yaml")
    74  		Ω(err).ShouldNot(HaveOccurred())
    75  	})
    76  
    77  	It("should have created a branch order file", func() {
    78  		_, err := os.Stat("build_order.txt")
    79  		Ω(err).ShouldNot(HaveOccurred())
    80  	})
    81  
    82  	It("should have created a directory for the env", func() {
    83  		_, err := os.Stat("env")
    84  		Ω(err).ShouldNot(HaveOccurred())
    85  	})
    86  
    87  	It("should have created environment tfvars inside the env directory", func() {
    88  		_, err := os.Stat("env/dev.tfvars")
    89  		Ω(err).ShouldNot(HaveOccurred())
    90  		_, err = os.Stat("env/prod.tfvars")
    91  		Ω(err).ShouldNot(HaveOccurred())
    92  	})
    93  
    94  })