use t.Cleanup and prefer assert.NoError over .Nil (#309)

Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
Stephen Solka 2020-07-20 10:35:43 -04:00 committed by GitHub
parent f00aa08417
commit 85a47838fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,39 +35,39 @@ func TestFindGitSlug(t *testing.T) {
for _, tt := range slugTests { for _, tt := range slugTests {
provider, slug, err := findGitSlug(tt.url) provider, slug, err := findGitSlug(tt.url)
assert.Nil(err) assert.NoError(err)
assert.Equal(tt.provider, provider) assert.Equal(tt.provider, provider)
assert.Equal(tt.slug, slug) assert.Equal(tt.slug, slug)
} }
} }
func testDir(t *testing.T) string {
basedir, err := ioutil.TempDir("", "act-test")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(basedir) })
return basedir
}
func TestFindGitRemoteURL(t *testing.T) { func TestFindGitRemoteURL(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
basedir, err := ioutil.TempDir("", "act-test") basedir := testDir(t)
defer os.RemoveAll(basedir)
assert.Nil(err)
gitConfig() gitConfig()
err = gitCmd("init", basedir) err := gitCmd("init", basedir)
assert.Nil(err) assert.NoError(err)
remoteURL := "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo-name" remoteURL := "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo-name"
err = gitCmd("config", "-f", fmt.Sprintf("%s/.git/config", basedir), "--add", "remote.origin.url", remoteURL) err = gitCmd("config", "-f", fmt.Sprintf("%s/.git/config", basedir), "--add", "remote.origin.url", remoteURL)
assert.Nil(err) assert.NoError(err)
u, err := findGitRemoteURL(basedir) u, err := findGitRemoteURL(basedir)
assert.Nil(err) assert.NoError(err)
assert.Equal(remoteURL, u) assert.Equal(remoteURL, u)
} }
func TestGitFindRef(t *testing.T) { func TestGitFindRef(t *testing.T) {
basedir, err := ioutil.TempDir("", "act-test") basedir := testDir(t)
defer os.RemoveAll(basedir)
assert.NoError(t, err)
gitConfig() gitConfig()
for name, tt := range map[string]struct { for name, tt := range map[string]struct {