|
| 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 | +funcTestCurrentOrganization(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:=rangeorgs { |
| 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(chanerror) |
| 36 | +gofunc() { |
| 37 | +errC<-inv.Run() |
| 38 | +}() |
| 39 | +require.NoError(t,<-errC) |
| 40 | +pty.ExpectMatch(first.OrganizationID.String()) |
| 41 | +}) |
| 42 | +} |