func TestFilterConfigWeb(t *testing.T) { c := NewConfig("", "test/Simple/captain.yml", false) assert.Equal(t, 2, len(c.GetApps()), "Should return 2 apps") c.FilterConfig("web") assert.Equal(t, 1, len(c.GetApps()), "Should return 1 app") assert.Equal(t, "Dockerfile", c.GetApp("web").Build, "Should return web Build field") }
func TestFilterConfigEmpty(t *testing.T) { c := NewConfig("", "test/Simple/captain.yml", false) assert.Equal(t, 2, len(c.GetApps()), "Should return 2 apps") res := c.FilterConfig("") assert.True(t, res, "Should return true") assert.Equal(t, 2, len(c.GetApps()), "Should return 2 apps") }
func TestFilterConfigNonExistent(t *testing.T) { c := NewConfig("", "test/Simple/captain.yml", false) assert.Equal(t, 2, len(c.GetApps()), "Should return 2 apps") res := c.FilterConfig("nonexistent") assert.False(t, res, "Should return false") assert.Equal(t, 0, len(c.GetApps()), "Should return 0 apps") }
func TestTagNonexistingImage(t *testing.T) { app := App{Image: "golang"} res := tagImage(app, "nonexist", "testing") expected := errors.New("no such image") assert.Equal(t, expected, res, "Docker tag should return an error") println() }
func TestGitIsDirty(t *testing.T) { assert.Equal(t, false, isDirty(), "Git should not have local changes") }
func TestGitGetBranch(t *testing.T) { assert.Equal(t, "master", getBranch(), "Git branch should be master") }
func TestExecute(t *testing.T) { res := execute("echo", "testing") assert.Equal(t, nil, res, "it should execute without errors") }
func TestOnelinerTrimmed(t *testing.T) { res, _ := oneliner("echo", "testing with spaces ") assert.Equal(t, "testing with spaces", res, "it should return the trimmed result") }
func TestGitGetBranchAllBranches(t *testing.T) { assert.Equal(t, []string{"master"}, getBranches(true), "Git branch should be master") }
func TestGitGetRevisionFullSha(t *testing.T) { assert.Equal(t, 40, len(getRevision(true)), "Git revision should have a length of 40 chars") }
func TestImageExist(t *testing.T) { app := App{Image: "golang"} exist := imageExist(app, "1.4") assert.Equal(t, true, exist, "Docker image golang:1.4 should exist") }
func TestConfigFiles(t *testing.T) { options.config = "captain.yml" c := configFile(options) sl := "captain.yml" assert.Equal(t, sl, c, "Should return possible config files") }
func TestGetApp(t *testing.T) { options.config = "test/Simple/captain.yml" c := NewConfig(options, false) app := c.GetApp("web") assert.Equal(t, "harbur/test_web", app.Image, "Should return web image") }
func TestGitIsGit(t *testing.T) { assert.Equal(t, true, isGit(), "There should be a git repository") }
func TestImageDoesNotExist(t *testing.T) { app := App{Image: "golang"} exist := imageExist(app, "nonexist") assert.Equal(t, false, exist, "Docker image golang:nonexist should not exist") }
func TestGitGetRevision(t *testing.T) { assert.Equal(t, 7, len(getRevision()), "Git revision should have length 7 chars") }
func TestColorCodes(t *testing.T) { assert.Equal(t, "\x1b[32mhello\x1b[0m", colorInfo("hello"), "they should be equal") assert.Equal(t, "\x1b[33mhello\x1b[0m", colorWarn("hello"), "they should be equal") assert.Equal(t, "\x1b[31mhello\x1b[0m", colorErr("hello"), "they should be equal") }