Skip to content
This repository was archived by the owner on Feb 7, 2020. It is now read-only.

Commit 2176bf0

Browse files
committed
feat(ci): improve test coverage
1 parent 7930cd3 commit 2176bf0

15 files changed

+295
-2
lines changed

commands/ci_dump_meta.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ type CiDumpMetaCommand struct {
4747
}
4848

4949
func (c *CiDumpMetaCommand) Run(args []string) int {
50-
5150
cmdFlags := flag.NewFlagSet("ci:meta", flag.ContinueOnError)
5251
cmdFlags.Usage = func() {
5352
c.Ui.Output(c.Help())

commands/ci_dump_meta_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,20 @@ func Test_Ci_Dump_Meta_With_Values(t *testing.T) {
9898

9999
os.Remove(path)
100100
}
101+
102+
func Test_Ci_Dump_Meta_Help(t *testing.T) {
103+
c := &CiDumpMetaCommand{
104+
Ui: &cli.MockUi{},
105+
}
106+
107+
assert.True(t, len(c.Help()) > 0)
108+
assert.True(t, len(c.Synopsis()) > 0)
109+
}
110+
111+
func Test_Ci_Dump_Meta_InvalidRun(t *testing.T) {
112+
c := &CiDumpMetaCommand{
113+
Ui: &cli.MockUi{},
114+
}
115+
116+
assert.Equal(t, 1, c.Run([]string{"--foobar"}))
117+
}

commands/ci_dump_revision_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,20 @@ func Test_Ci_Dump_Revision(t *testing.T) {
4848

4949
os.Remove(path)
5050
}
51+
52+
func Test_Ci_Revision_Help(t *testing.T) {
53+
c := &CiDumpRevisionCommand{
54+
Ui: &cli.MockUi{},
55+
}
56+
57+
assert.True(t, len(c.Help()) > 0)
58+
assert.True(t, len(c.Synopsis()) > 0)
59+
}
60+
61+
func Test_Ci_Dump_Revision_InvalidRun(t *testing.T) {
62+
c := &CiDumpRevisionCommand{
63+
Ui: &cli.MockUi{},
64+
}
65+
66+
assert.Equal(t, 1, c.Run([]string{"--foobar"}))
67+
}

commands/dump_readme.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package commands
77

88
import (
9+
"flag"
910
"fmt"
1011
"github.com/mitchellh/cli"
1112
"sort"
@@ -19,6 +20,18 @@ type DumpReadmeCommand struct {
1920
}
2021

2122
func (c *DumpReadmeCommand) Run(args []string) int {
23+
24+
cmdFlags := flag.NewFlagSet("dump:readme", flag.ContinueOnError)
25+
cmdFlags.Usage = func() {
26+
c.Ui.Output(c.Help())
27+
}
28+
29+
cmdFlags.BoolVar(&c.Verbose, "verbose", false, "")
30+
31+
if err := cmdFlags.Parse(args); err != nil {
32+
return 1
33+
}
34+
2235
mk := make([]string, len(c.Commands))
2336

2437
i := 0
@@ -54,5 +67,5 @@ func (c *DumpReadmeCommand) Synopsis() string {
5467
}
5568

5669
func (c *DumpReadmeCommand) Help() string {
57-
return strings.TrimSpace("")
70+
return strings.TrimSpace("Dump the command readme.")
5871
}

commands/dump_readme_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,20 @@ func Test_Dump_Readme(t *testing.T) {
2121

2222
assert.Equal(t, 0, code)
2323
}
24+
25+
func Test_Dump_Readme_Help(t *testing.T) {
26+
c := &DumpReadmeCommand{
27+
Ui: &cli.MockUi{},
28+
}
29+
30+
assert.True(t, len(c.Help()) > 0)
31+
assert.True(t, len(c.Synopsis()) > 0)
32+
}
33+
34+
func Test_Dump_Readme_InvalidRun(t *testing.T) {
35+
c := &DumpReadmeCommand{
36+
Ui: &cli.MockUi{},
37+
}
38+
39+
assert.Equal(t, 1, c.Run([]string{"--foobar"}))
40+
}

commands/project_build_artifacts_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,20 @@ func Test_Project_Builds_Artifacts(t *testing.T) {
100100
})
101101

102102
}
103+
104+
func Test_Project_Builds_Artifacts_Help(t *testing.T) {
105+
c := &ProjectBuildArtifactCommand{
106+
Ui: &cli.MockUi{},
107+
}
108+
109+
assert.True(t, len(c.Help()) > 0)
110+
assert.True(t, len(c.Synopsis()) > 0)
111+
}
112+
113+
func Test_Project_Builds_Artifacts_InvalidRun(t *testing.T) {
114+
c := &ProjectBuildArtifactCommand{
115+
Ui: &cli.MockUi{},
116+
}
117+
118+
assert.Equal(t, 1, c.Run([]string{"--foobar"}))
119+
}

commands/project_builds_list_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,20 @@ func Test_Project_BuildsList_From_Args(t *testing.T) {
5252
assert.Equal(t, 0, code)
5353
})
5454
}
55+
56+
func Test_Project_BuildsList_Help(t *testing.T) {
57+
c := &ProjectBuildsListCommand{
58+
Ui: &cli.MockUi{},
59+
}
60+
61+
assert.True(t, len(c.Help()) > 0)
62+
assert.True(t, len(c.Synopsis()) > 0)
63+
}
64+
65+
func Test_Project_BuildsList_InvalidRun(t *testing.T) {
66+
c := &ProjectBuildsListCommand{
67+
Ui: &cli.MockUi{},
68+
}
69+
70+
assert.Equal(t, 1, c.Run([]string{"--foobar"}))
71+
}

commands/project_list_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,20 @@ func Test_Project_List(t *testing.T) {
4848
assert.Equal(t, expected, ui.OutputWriter.String())
4949
})
5050
}
51+
52+
func Test_Project_List_Help(t *testing.T) {
53+
c := &ProjectsListCommand{
54+
Ui: &cli.MockUi{},
55+
}
56+
57+
assert.True(t, len(c.Help()) > 0)
58+
assert.True(t, len(c.Synopsis()) > 0)
59+
}
60+
61+
func Test_Project_List_InvalidRun(t *testing.T) {
62+
c := &ProjectsListCommand{
63+
Ui: &cli.MockUi{},
64+
}
65+
66+
assert.Equal(t, 1, c.Run([]string{"--foobar"}))
67+
}

commands/s3_archive_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright © 2016 Thomas Rabaix <thomas.rabaix@gmail.com>.
2+
//
3+
// Use of this source code is governed by an MIT-style
4+
// license that can be found in the LICENSE file.
5+
6+
package commands
7+
8+
import (
9+
"github.com/mitchellh/cli"
10+
"github.com/stretchr/testify/assert"
11+
"testing"
12+
)
13+
14+
func Test_S3ArchiveCommand_Help(t *testing.T) {
15+
c := &S3ArchiveCommand{
16+
Ui: &cli.MockUi{},
17+
}
18+
19+
assert.True(t, len(c.Help()) > 0)
20+
assert.True(t, len(c.Synopsis()) > 0)
21+
}
22+
23+
func Test_S3ArchiveCommand_InvalidRun(t *testing.T) {
24+
c := &S3ArchiveCommand{
25+
Ui: &cli.MockUi{},
26+
}
27+
28+
assert.Equal(t, 1, c.Run([]string{"--foobar"}))
29+
}

commands/s3_extract_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright © 2016 Thomas Rabaix <thomas.rabaix@gmail.com>.
2+
//
3+
// Use of this source code is governed by an MIT-style
4+
// license that can be found in the LICENSE file.
5+
6+
package commands
7+
8+
import (
9+
"github.com/mitchellh/cli"
10+
"github.com/stretchr/testify/assert"
11+
"testing"
12+
)
13+
14+
func Test_S3ExtractCommand_Help(t *testing.T) {
15+
c := &S3ExtractCommand{
16+
Ui: &cli.MockUi{},
17+
}
18+
19+
assert.True(t, len(c.Help()) > 0)
20+
assert.True(t, len(c.Synopsis()) > 0)
21+
}
22+
23+
func Test_S3ExtractCommand_InvalidRun(t *testing.T) {
24+
c := &S3ExtractCommand{
25+
Ui: &cli.MockUi{},
26+
}
27+
28+
assert.Equal(t, 1, c.Run([]string{"--foobar"}))
29+
}

0 commit comments

Comments
 (0)