Skip to content

Commit

Permalink
test: cleaning up files/dirs at end of runs
Browse files Browse the repository at this point in the history
  • Loading branch information
azemetre committed May 23, 2023
1 parent c46fdfa commit 1e941e9
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions pkg/piscator/piscator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"errors"
"io"
"net/http"
"os"
"reflect"
"strconv"
"strings"
"testing"
"time"
)
Expand Down Expand Up @@ -76,7 +78,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: true,
isOrg: false,
Expand Down Expand Up @@ -104,7 +106,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: true,
isOrg: false,
Expand Down Expand Up @@ -132,7 +134,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: true,
isOrg: false,
Expand Down Expand Up @@ -160,7 +162,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: true,
isOrg: false,
Expand Down Expand Up @@ -188,7 +190,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: true,
isOrg: true,
Expand Down Expand Up @@ -216,7 +218,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: true,
isOrg: true,
Expand Down Expand Up @@ -244,7 +246,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: true,
isOrg: true,
Expand Down Expand Up @@ -272,7 +274,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: true,
isOrg: true,
Expand Down Expand Up @@ -300,7 +302,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: false,
isOrg: false,
Expand Down Expand Up @@ -328,7 +330,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: false,
isOrg: false,
Expand Down Expand Up @@ -356,7 +358,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: false,
isOrg: false,
Expand Down Expand Up @@ -398,7 +400,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: false,
isOrg: true,
Expand Down Expand Up @@ -440,7 +442,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: false,
isOrg: true,
Expand Down Expand Up @@ -468,7 +470,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "user1",
name: "user1-makefile",
token: "token",
isSelf: false,
isOrg: true,
Expand All @@ -482,7 +484,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "forked repos",
name: "forked repos-makefile",
token: "token",
isSelf: false,
isOrg: true,
Expand Down Expand Up @@ -521,7 +523,7 @@ func TestGetRepos(t *testing.T) {
wantError: false,
},
{
name: "forked repos",
name: "forked repos-makefile",
token: "token",
isSelf: false,
isOrg: true,
Expand Down Expand Up @@ -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)
}
}
}()
})
}
}
Expand Down Expand Up @@ -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{},
}
Expand Down Expand Up @@ -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)
}
}()
})

}
}

0 comments on commit 1e941e9

Please sign in to comment.