@@ -43,3 +43,37 @@ func TestCurrentOrganization(t *testing.T) {
43
43
pty .ExpectMatch (first .OrganizationID .String ())
44
44
})
45
45
}
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