forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplatelist_test.go
More file actions
73 lines (57 loc) · 1.97 KB
/
templatelist_test.go
File metadata and controls
73 lines (57 loc) · 1.97 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
package cli_test
import (
"sort"
"testing"
"github.com/stretchr/testify/require"
"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/pty/ptytest"
)
func TestTemplateList(t *testing.T) {
t.Parallel()
t.Run("ListTemplates", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)
firstVersion := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
_ = coderdtest.AwaitTemplateVersionJob(t, client, firstVersion.ID)
firstTemplate := coderdtest.CreateTemplate(t, client, user.OrganizationID, firstVersion.ID)
secondVersion := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
_ = coderdtest.AwaitTemplateVersionJob(t, client, secondVersion.ID)
secondTemplate := coderdtest.CreateTemplate(t, client, user.OrganizationID, secondVersion.ID)
cmd, root := clitest.New(t, "templates", "list")
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t)
cmd.SetIn(pty.Input())
cmd.SetOut(pty.Output())
errC := make(chan error)
go func() {
errC <- cmd.Execute()
}()
// expect that templates are listed alphebetically
var templatesList = []string{firstTemplate.Name, secondTemplate.Name}
sort.Strings(templatesList)
require.NoError(t, <-errC)
for _, name := range templatesList {
pty.ExpectMatch(name)
}
})
t.Run("NoTemplates", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{})
coderdtest.CreateFirstUser(t, client)
cmd, root := clitest.New(t, "templates", "list")
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t)
cmd.SetIn(pty.Input())
cmd.SetErr(pty.Output())
errC := make(chan error)
go func() {
errC <- cmd.Execute()
}()
require.NoError(t, <-errC)
pty.ExpectMatch("No templates found in")
pty.ExpectMatch(coderdtest.FirstUserParams.Username)
pty.ExpectMatch("Create one:")
})
}