diff --git a/pkg/piscator/piscator_test.go b/pkg/piscator/piscator_test.go index c20757c..ac7f145 100644 --- a/pkg/piscator/piscator_test.go +++ b/pkg/piscator/piscator_test.go @@ -6,8 +6,10 @@ import ( "errors" "io" "net/http" + "os" "reflect" "strconv" + "strings" "testing" "time" ) @@ -76,7 +78,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: true, isOrg: false, @@ -104,7 +106,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: true, isOrg: false, @@ -132,7 +134,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: true, isOrg: false, @@ -160,7 +162,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: true, isOrg: false, @@ -188,7 +190,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: true, isOrg: true, @@ -216,7 +218,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: true, isOrg: true, @@ -244,7 +246,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: true, isOrg: true, @@ -272,7 +274,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: true, isOrg: true, @@ -300,7 +302,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: false, isOrg: false, @@ -328,7 +330,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: false, isOrg: false, @@ -356,7 +358,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: false, isOrg: false, @@ -398,7 +400,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: false, isOrg: true, @@ -440,7 +442,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: false, isOrg: true, @@ -468,7 +470,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "user1", + name: "user1-makefile", token: "token", isSelf: false, isOrg: true, @@ -482,7 +484,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "forked repos", + name: "forked repos-makefile", token: "token", isSelf: false, isOrg: true, @@ -521,7 +523,7 @@ func TestGetRepos(t *testing.T) { wantError: false, }, { - name: "forked repos", + name: "forked repos-makefile", token: "token", isSelf: false, isOrg: true, @@ -680,6 +682,16 @@ func TestGetRepos(t *testing.T) { } } } + + // test cleanup, after it has run + defer func() { + if strings.Contains(tt.name, "-makefile") { + err := os.Remove("repos.json") + if err != nil { + t.Errorf("Failed to remove repos.json file: %v", err) + } + } + }() }) } } @@ -801,7 +813,7 @@ func (m MockCommandExecutor) ExecuteCommandInDir(dir, name string, arg ...string return []byte("ok"), nil } -func TestCloneReposFromJson_ExecuteCommandError(t *testing.T) { +func TestCloneReposFromJson(t *testing.T) { successExecutor := MockCommandExecutor{ errors: map[string]error{}, } @@ -834,6 +846,15 @@ func TestCloneReposFromJson_ExecuteCommandError(t *testing.T) { if (err != nil) != tt.wantError { t.Errorf("CloneReposFromJson() error = %v, wantError %v", err, tt.wantError) } + + // test cleanup, after it has run + defer func() { + err := os.RemoveAll(tt.name) + if err != nil { + t.Errorf("Failed to remove %s directory: %v", tt.name, err) + } + }() }) + } }