func TestStrip(t *testing.T) { util.InTestDir(func() { for _, f := range []string{"CHANGELOG.md", "README.md", "metadata.rb"} { ioutil.WriteFile(f, []byte{}, 0644) } for _, d := range []string{"attributes", "recipes", "tmp"} { os.Mkdir(d, 0755) } cb, _ := NewCookbook(".") assert.NoError(t, cb.Strip()) expect := []string{ "README.md", "attributes", "metadata.rb", "recipes", } files, err := ioutil.ReadDir(".") if err != nil { panic(err) } var actual []string for _, f := range files { actual = append(actual, f.Name()) } assert.Equal(t, expect, actual) }) }
func TestAutoResolve_NoCookbooks(t *testing.T) { lastCmd = []string{} util.InTestDir(func() { assert.EqualError(t, AutoResolve(CookbookPath), "cookbooks could not be found") }) assert.Equal(t, []string{}, lastCmd) }
func TestResolve_Librarian(t *testing.T) { lastCmd = []string{} util.InTestDir(func() { os.MkdirAll(CookbookPath, 0755) assert.NoError(t, Resolve("librarian", CookbookPath)) }) assert.Equal(t, []string{"librarian-chef", "install", "--path", CookbookPath}, lastCmd) }
func TestAutoResolve_Dir(t *testing.T) { lastCmd = []string{} util.InTestDir(func() { ioutil.WriteFile("metadata.rb", []byte(`name "cats"`), 0644) assert.NoError(t, AutoResolve(CookbookPath)) }) assert.Equal(t, []string{"rsync", "--archive", "--delete", "--compress", "metadata.rb", CookbookPath + "/cats"}, lastCmd) }
func TestAutoResolve_Librarian(t *testing.T) { lastCmd = []string{} util.InTestDir(func() { ioutil.WriteFile("Cheffile", []byte{}, 0644) os.MkdirAll(CookbookPath, 0755) assert.NoError(t, AutoResolve(CookbookPath)) }) assert.Equal(t, []string{"librarian-chef", "install", "--path", CookbookPath}, lastCmd) }
func TestAutoResolve_Berkshelf(t *testing.T) { lastCmd = []string{} util.InTestDir(func() { ioutil.WriteFile("Berksfile", []byte{}, 0644) os.MkdirAll(CookbookPath, 0755) AutoResolve(CookbookPath) }) assert.Equal(t, []string{"ruby", "-e"}, lastCmd[:2]) assert.True(t, strings.Contains(lastCmd[2], `require "berkshelf"`)) assert.True(t, strings.Contains(lastCmd[2], fmt.Sprintf(`.vendor("%s")`, CookbookPath))) }
func TestPrepareFiles(t *testing.T) { util.InTestDir(func() { os.MkdirAll(".chef-runner/sandbox", 0755) p := Provisioner{ SandboxPath: ".chef-runner/sandbox", RootPath: "/tmp/chef-runner", } assert.NoError(t, p.PrepareFiles()) json, err := ioutil.ReadFile(".chef-runner/sandbox/dna.json") assert.NoError(t, err) assert.Equal(t, "{}\n", string(json)) expect := "cookbook_path \"/tmp/chef-runner/cookbooks\"\n" expect += "ssl_verify_mode :verify_peer\n" config, err := ioutil.ReadFile(".chef-runner/sandbox/solo.rb") assert.NoError(t, err) assert.Equal(t, expect, string(config)) }) }