Skip to content

Commit 438e69d

Browse files
committed
Add unit test
1 parent 50cdb32 commit 438e69d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

cli/organization_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cli_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
8+
"github.com/coder/coder/v2/cli/clitest"
9+
"github.com/coder/coder/v2/coderd/coderdtest"
10+
"github.com/coder/coder/v2/codersdk"
11+
"github.com/coder/coder/v2/pty/ptytest"
12+
"github.com/coder/coder/v2/testutil"
13+
)
14+
15+
func TestCurrentOrganization(t *testing.T) {
16+
t.Parallel()
17+
18+
t.Run("OnlyID", func(t *testing.T) {
19+
t.Parallel()
20+
client := coderdtest.New(t, nil)
21+
first := coderdtest.CreateFirstUser(t, client)
22+
23+
ctx := testutil.Context(t, testutil.WaitMedium)
24+
orgs := []string{"foo", "bar"}
25+
for _, orgName := range orgs {
26+
_, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
27+
Name: orgName,
28+
})
29+
require.NoError(t, err)
30+
}
31+
32+
inv, root := clitest.New(t, "organizations", "current", "--only-id")
33+
clitest.SetupConfig(t, client, root)
34+
pty := ptytest.New(t).Attach(inv)
35+
errC := make(chan error)
36+
go func() {
37+
errC <- inv.Run()
38+
}()
39+
require.NoError(t, <-errC)
40+
pty.ExpectMatch(first.OrganizationID.String())
41+
})
42+
}

0 commit comments

Comments
 (0)