Skip to content

Commit

Permalink
Merge pull request #1205 from luhring/git-side-effect
Browse files Browse the repository at this point in the history
fix(git): test flaking from env side effects
  • Loading branch information
imjasonh authored Sep 24, 2024
2 parents cee040f + a245150 commit b5c248c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/git/git_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package git

import (
"os"
"testing"

gitHttp "github.com/go-git/go-git/v5/plumbing/transport/http"
Expand Down Expand Up @@ -123,10 +122,10 @@ func TestGetGitAuth(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.envToken != "" {
os.Setenv("GITHUB_TOKEN", tt.envToken)
defer os.Unsetenv("GITHUB_TOKEN")
}
// Important: Don't affect or be affected by the actual environment. This helps
// to make the test less flaky, and avoids disrupting the developer's local
// setup.
t.Setenv("GITHUB_TOKEN", tt.envToken)

auth, err := GetGitAuth(tt.gitURL)

Expand Down

0 comments on commit b5c248c

Please sign in to comment.