forked from git-time-metric/gtm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_test.go
More file actions
100 lines (76 loc) · 2.37 KB
/
clean_test.go
File metadata and controls
100 lines (76 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2016 Michael Schenk. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package command
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/git-time-metric/gtm/project"
"github.com/git-time-metric/gtm/util"
"github.com/mitchellh/cli"
)
func TestCleanYes(t *testing.T) {
repo := util.NewTestRepo(t, false)
defer repo.Remove()
repo.Seed()
os.Chdir(repo.Workdir())
(InitCmd{UI: new(cli.MockUi)}).Run([]string{})
ui := new(cli.MockUi)
c := CleanCmd{UI: ui}
args := []string{"-yes"}
rc := c.Run(args)
if rc != 0 {
t.Errorf("gtm clean(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter.String())
}
}
func TestTerminalOnly(t *testing.T) {
repo := util.NewTestRepo(t, false)
defer repo.Remove()
repo.Seed()
os.Chdir(repo.Workdir())
(InitCmd{UI: new(cli.MockUi)}).Run([]string{})
ui := new(cli.MockUi)
c := CleanCmd{UI: ui}
args := []string{"-terminal-only", "-yes"}
rc := c.Run(args)
if rc != 0 {
t.Errorf("gtm clean(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter.String())
}
}
func TestAppOnly(t *testing.T) {
repo := util.NewTestRepo(t, false)
defer repo.Remove()
repo.Seed()
os.Chdir(repo.Workdir())
repo.SaveFile("browser.app", project.GTMDir, "")
repo.SaveFile("1458496803.event", project.GTMDir, filepath.Join("event", "event.go"))
repo.SaveFile("1458497804.event", project.GTMDir, filepath.Join(project.GTMDir, "browser.app"))
(InitCmd{UI: new(cli.MockUi)}).Run([]string{})
ui := new(cli.MockUi)
c := CleanCmd{UI: ui}
args := []string{"-app-only", "-yes"}
rc := c.Run(args)
if rc != 0 {
t.Errorf("gtm clean(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter.String())
}
if !repo.FileExists("1458496803.event", project.GTMDir) {
t.Errorf("gtm clean(%+v), want non-app event to not be deleted, but was deleted", args)
}
if repo.FileExists("1458497804.event", project.GTMDir) {
t.Errorf("gtm clean(%+v), want app event to be deleted, but was found", args)
}
}
func TestCleanInvalidOption(t *testing.T) {
ui := new(cli.MockUi)
c := CleanCmd{UI: ui}
args := []string{"-invalid"}
rc := c.Run(args)
if rc != 1 {
t.Errorf("gtm clean(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter)
}
if !strings.Contains(ui.OutputWriter.String(), "Usage:") {
t.Errorf("gtm clean(%+v), want 'Usage:' got %d, %s", args, rc, ui.OutputWriter.String())
}
}