Skip to content

Commit 8741a03

Browse files
committed
Add file checking for some test cases of app support
1 parent 5d25674 commit 8741a03

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

command/clean_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ package command
66

77
import (
88
"os"
9+
"path/filepath"
910
"strings"
1011
"testing"
1112

13+
"github.com/git-time-metric/gtm/project"
1214
"github.com/git-time-metric/gtm/util"
1315
"github.com/mitchellh/cli"
1416
)
@@ -57,6 +59,10 @@ func TestAppOnly(t *testing.T) {
5759
repo.Seed()
5860
os.Chdir(repo.Workdir())
5961

62+
repo.SaveFile("browser.app", project.GTMDir, "")
63+
repo.SaveFile("1458496803.event", project.GTMDir, filepath.Join("event", "event.go"))
64+
repo.SaveFile("1458497804.event", project.GTMDir, filepath.Join(project.GTMDir, "browser.app"))
65+
6066
(InitCmd{UI: new(cli.MockUi)}).Run([]string{})
6167

6268
ui := new(cli.MockUi)
@@ -68,6 +74,14 @@ func TestAppOnly(t *testing.T) {
6874
if rc != 0 {
6975
t.Errorf("gtm clean(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter.String())
7076
}
77+
78+
if !repo.FileExists("1458496803.event", project.GTMDir) {
79+
t.Errorf("gtm clean(%+v), want non-app event to not be deleted, but was deleted", args)
80+
}
81+
82+
if repo.FileExists("1458497804.event", project.GTMDir) {
83+
t.Errorf("gtm clean(%+v), want app event to be deleted, but was found", args)
84+
}
7185
}
7286

7387
func TestCleanInvalidOption(t *testing.T) {

util/test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ func (t TestRepo) SaveFile(filename, subdir, content string) {
139139
CheckFatal(t.test, err)
140140
}
141141

142+
// FileExists Checks if a file exists in the repo folder
143+
func (t TestRepo) FileExists(filename, subdir string) bool {
144+
_, err := os.Stat(filepath.Join(subdir, filename))
145+
return !os.IsNotExist(err)
146+
}
147+
142148
// Clone creates a clone of this repo
143149
func (t TestRepo) Clone() TestRepo {
144150
path, err := ioutil.TempDir("", "gtm")

0 commit comments

Comments
 (0)