Skip to content

Commit 3bd5f2f

Browse files
committed
Add unit test for switch cli
1 parent efce093 commit 3bd5f2f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

cli/organization_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,37 @@ func TestCurrentOrganization(t *testing.T) {
4343
pty.ExpectMatch(first.OrganizationID.String())
4444
})
4545
}
46+
47+
func TestOrganizationSwitch(t *testing.T) {
48+
t.Parallel()
49+
50+
t.Run("Switch", func(t *testing.T) {
51+
t.Parallel()
52+
ownerClient := coderdtest.New(t, nil)
53+
first := coderdtest.CreateFirstUser(t, ownerClient)
54+
// Owner is required to make orgs
55+
client, _ := coderdtest.CreateAnotherUser(t, ownerClient, first.OrganizationID, rbac.RoleOwner())
56+
57+
ctx := testutil.Context(t, testutil.WaitMedium)
58+
orgs := []string{"foo", "bar"}
59+
for _, orgName := range orgs {
60+
_, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
61+
Name: orgName,
62+
})
63+
require.NoError(t, err)
64+
}
65+
66+
exp, err := client.OrganizationByName(ctx, codersdk.Me, "foo")
67+
require.NoError(t, err)
68+
69+
inv, root := clitest.New(t, "organizations", "switch", "foo")
70+
clitest.SetupConfig(t, client, root)
71+
pty := ptytest.New(t).Attach(inv)
72+
errC := make(chan error)
73+
go func() {
74+
errC <- inv.Run()
75+
}()
76+
require.NoError(t, <-errC)
77+
pty.ExpectMatch(exp.ID.String())
78+
})
79+
}

0 commit comments

Comments
 (0)