-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_test.go
More file actions
60 lines (53 loc) · 1.53 KB
/
cli_test.go
File metadata and controls
60 lines (53 loc) · 1.53 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
//go:generate mockgen -source=cli.go -destination=cli_mocks_test.go -package=main_test
package main_test
import (
"bytes"
"io"
"testing"
"testing/fstest"
"github.com/stretchr/testify/assert"
. "github.com/stroiman/muxify"
"go.uber.org/mock/gomock"
)
func TestCliLaunchProject(t *testing.T) {
controller := gomock.NewController(t)
mock := NewMockRunner(controller)
cli := CLI{mock, fakeOs, io.Discard}
call := mock.EXPECT().Run(gomock.Any())
var actualProject Project
call.Do(func(project Project) {
actualProject = project
})
cli.Run([]string{"muxify", "launch", "Project 1"})
controller.Finish()
assert.Equal(t, Project{Name: "Project 1"}, actualProject)
}
func TestCliLaunchProjectWithVerbose(t *testing.T) {
controller := gomock.NewController(t)
mock := NewMockRunner(controller)
cli := CLI{mock, fakeOs, io.Discard}
call := mock.EXPECT().Run(gomock.Any())
var actualProject Project
call.Do(func(project Project) {
actualProject = project
})
cli.Run([]string{"muxify", "-v", "launch", "Project 1"})
controller.Finish()
assert.Equal(t, Project{Name: "Project 1"}, actualProject)
}
func TestCliListProjects(t *testing.T) {
var b bytes.Buffer
cli := CLI{nil, fakeOs, &b}
cli.Run([]string{"muxify", "list"})
assert.Equal(t, "Project 1\nProject 2\n", b.String())
}
var configuration = `projects:
- name: Project 1
- name: Project 2
`
var fakeOs = FakeOS{
files: fstest.MapFS{"/users/foo/.config/muxify/projects.yaml": &fstest.MapFile{
Data: []byte(configuration),
}},
env: map[string]string{"HOME": "/users/foo"},
}