mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
feat: set organization context in coder organizations (#12265)
* feat: add coder organizations set to change org context `coder organizations set <org>`
This commit is contained in:
@ -74,3 +74,37 @@ func TestCurrentOrganization(t *testing.T) {
|
||||
pty.ExpectMatch(orgs["bar"].ID.String())
|
||||
})
|
||||
}
|
||||
|
||||
func TestOrganizationSwitch(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("Switch", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ownerClient := coderdtest.New(t, nil)
|
||||
first := coderdtest.CreateFirstUser(t, ownerClient)
|
||||
// Owner is required to make orgs
|
||||
client, _ := coderdtest.CreateAnotherUser(t, ownerClient, first.OrganizationID, rbac.RoleOwner())
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
orgs := []string{"foo", "bar"}
|
||||
for _, orgName := range orgs {
|
||||
_, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
|
||||
Name: orgName,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
exp, err := client.OrganizationByName(ctx, "foo")
|
||||
require.NoError(t, err)
|
||||
|
||||
inv, root := clitest.New(t, "organizations", "set", "foo")
|
||||
clitest.SetupConfig(t, client, root)
|
||||
pty := ptytest.New(t).Attach(inv)
|
||||
errC := make(chan error)
|
||||
go func() {
|
||||
errC <- inv.Run()
|
||||
}()
|
||||
require.NoError(t, <-errC)
|
||||
pty.ExpectMatch(exp.ID.String())
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user