func TestStripSuffixes(t *testing.T) { strs := []string{"a.git", "b.git", "c.git", "d"} newStrs := stripSuffixes(strs, dotGitSuffix) assert.Equal(t, len(newStrs), len(strs), "number of strings") for _, str := range newStrs { assert.False(t, strings.HasSuffix(str, dotGitSuffix), "string %s has suffix %s", str, dotGitSuffix) } }
func TestObjectExistsOtherErr(t *testing.T) { expectedErr := errors.New("other error") statter := &FakeObjectStatter{ Fn: func(context.Context, string) (storagedriver.FileInfo, error) { return storagedriver.FileInfoInternal{FileInfoFields: storagedriver.FileInfoFields{}}, expectedErr }, } exists, err := ObjectExists(statter, objPath) assert.Err(t, err, expectedErr) assert.False(t, exists, "object found when the statter errored") }
func TestObjectExistsNoObject(t *testing.T) { statter := &FakeObjectStatter{ Fn: func(context.Context, string) (storagedriver.FileInfo, error) { return storagedriver.FileInfoInternal{FileInfoFields: storagedriver.FileInfoFields{}}, storagedriver.PathNotFoundError{Path: objPath} }, } exists, err := ObjectExists(statter, objPath) assert.NoErr(t, err) assert.False(t, exists, "object found when it should be missing") assert.Equal(t, len(statter.Calls), 1, "number of StatObject calls") }
func TestCreatePreReceiveHook(t *testing.T) { const gitHome = "TestGitHome" gopath := os.Getenv("GOPATH") repoPath := filepath.Join(gopath, "src", "github.com", "deis", "builder", "testdata") assert.NoErr(t, createPreReceiveHook(gitHome, repoPath)) hookBytes, err := ioutil.ReadFile(filepath.Join(repoPath, "hooks", "pre-receive")) assert.NoErr(t, err) hookStr := string(hookBytes) gitHomeIdx := strings.Index(hookStr, fmt.Sprintf("GIT_HOME=%s", gitHome)) assert.False(t, gitHomeIdx == -1, "GIT_HOME was not found") }
func TestParse(t *testing.T) { //TODO: use gogenerate to generate valid html templates //http://godoc.org/github.com/arschles/gogenerate tmpl := ` <html> <head> <title>hello {{.name}}</title> </head> <body> {{.greeting}} </body> </html> ` fileName := "mytmpl.tmpl" tmplBytes := []byte(tmpl) expectedErr := errors.New("template not found") assetFunc := createValidAssetFunc(fileName, tmplBytes, expectedErr) tmpl1, err1 := New("test", assetFunc).Parse(fileName) assert.NoErr(t, err1) assert.False(t, tmpl1 == nil, "tmpl1 was nil when it should not have been") tmpl2, err2 := New("test1", assetFunc).Parse(fileName + fileName) assert.Err(t, err2, expectedErr) assert.True(t, tmpl2 == nil, "tmpl2 was not nil when it should have been") //TODO: check actual template output name := "Aaron" tmplData := map[string]string{ "name": name, } buf1 := bytes.NewBuffer([]byte{}) executeErr1 := tmpl1.Execute(buf1, tmplData) stdTmpl, stdTmplParseErr := template.New("referenceTest").Parse(tmpl) assert.NoErr(t, stdTmplParseErr) buf2 := bytes.NewBuffer([]byte{}) executeErr2 := stdTmpl.Execute(buf2, tmplData) assert.NoErr(t, executeErr1) assert.NoErr(t, executeErr2) bytes1 := buf1.Bytes() bytes2 := buf2.Bytes() assert.True(t, string(bytes1) == string(bytes2), "actual template output %s is not equal expected %s", string(bytes1), string(bytes2)) }
func TestBooleans(t *testing.T) { assert.True(t, true, "boolean true") assert.False(t, false, "boolean false") }
func TestDirHasGitSuffix(t *testing.T) { assert.True(t, dirHasGitSuffix("a.git"), "'a.git' reported no git suffix") assert.False(t, dirHasGitSuffix("abc"), "'a' reported git suffix") }