Skip to content

Commit 99867f3

Browse files
committed
make Tests more robust
1 parent b7d08fe commit 99867f3

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

integrations/repofiles_update_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,14 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
207207

208208
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
209209
expectedFileResponse := getExpectedFileResponseForRepofilesCreate(commitID)
210-
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
211-
assert.EqualValues(t, expectedFileResponse.Commit.SHA, fileResponse.Commit.SHA)
212-
assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
213-
assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
214-
assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
210+
assert.NotNil(t, expectedFileResponse)
211+
if expectedFileResponse != nil {
212+
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
213+
assert.EqualValues(t, expectedFileResponse.Commit.SHA, fileResponse.Commit.SHA)
214+
assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
215+
assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
216+
assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
217+
}
215218
})
216219
}
217220

modules/git/repo_branch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ type Branch struct {
4848

4949
// GetHEADBranch returns corresponding branch of HEAD.
5050
func (repo *Repository) GetHEADBranch() (*Branch, error) {
51+
if repo == nil {
52+
return nil, fmt.Errorf("nil repo")
53+
}
5154
stdout, err := NewCommand("symbolic-ref", "HEAD").RunInDir(repo.Path)
5255
if err != nil {
5356
return nil, err

modules/test/context_tests.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ func LoadRepoCommit(t *testing.T, ctx *context.Context) {
5858
defer gitRepo.Close()
5959
branch, err := gitRepo.GetHEADBranch()
6060
assert.NoError(t, err)
61-
ctx.Repo.Commit, err = gitRepo.GetBranchCommit(branch.Name)
62-
assert.NoError(t, err)
61+
assert.NotNil(t, branch)
62+
if branch != nil {
63+
ctx.Repo.Commit, err = gitRepo.GetBranchCommit(branch.Name)
64+
assert.NoError(t, err)
65+
}
6366
}
6467

6568
// LoadUser load a user into a test context.

0 commit comments

Comments
 (0)