Files
coder/enterprise/cli/root_test.go
T
Cian Johnston 26740cf00d chore(scripts/rules.go): broaden scope of testingWithOwnerUser linter (#10548)
* Updated testingWithOwnerUser ruleguard rule to detect:
  a) Passing client from coderdenttest.New() to clitest.SetupConfig() similar to what already exists for AGPL code
  b) Usage of any method of the owner client from coderdenttest.New() - all usages of the owner client must be justified with a `//nolint:gocritic` comment.
* Fixed resulting linter complaints.
* Added new coderdtest helpers CreateGroup and UpdateTemplateMeta.
* Modified check_enterprise_import.sh to ignore scripts/rules.go.
2023-11-08 14:54:48 +00:00

80 lines
1.9 KiB
Go

package cli_test
import (
"bytes"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/cli/config"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/enterprise/cli"
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
)
func newCLI(t *testing.T, args ...string) (*clibase.Invocation, config.Root) {
var root cli.RootCmd
cmd, err := root.Command(root.EnterpriseSubcommands())
require.NoError(t, err)
return clitest.NewWithCommand(t, cmd, args...)
}
func TestEnterpriseHandlersOK(t *testing.T) {
t.Parallel()
var root cli.RootCmd
cmd, err := root.Command(root.EnterpriseSubcommands())
require.NoError(t, err)
clitest.HandlersOK(t, cmd)
}
func TestCheckWarnings(t *testing.T) {
t.Parallel()
t.Run("LicenseWarningForPrivilegedRoles", func(t *testing.T) {
t.Parallel()
client, _ := coderdenttest.New(t, &coderdenttest.Options{
LicenseOptions: &coderdenttest.LicenseOptions{
ExpiresAt: time.Now().Add(time.Hour * 24),
},
})
inv, conf := newCLI(t, "list")
var buf bytes.Buffer
inv.Stderr = &buf
clitest.SetupConfig(t, client, conf) //nolint:gocritic // owners should see this
err := inv.Run()
require.NoError(t, err)
require.Contains(t, buf.String(), "Your license expires in 1 day.")
})
t.Run("NoLicenseWarningForRegularUser", func(t *testing.T) {
t.Parallel()
adminClient, admin := coderdenttest.New(t, &coderdenttest.Options{
LicenseOptions: &coderdenttest.LicenseOptions{
ExpiresAt: time.Now().Add(time.Hour * 24),
},
})
client, _ := coderdtest.CreateAnotherUser(t, adminClient, admin.OrganizationID)
inv, conf := newCLI(t, "list")
var buf bytes.Buffer
inv.Stderr = &buf
clitest.SetupConfig(t, client, conf)
err := inv.Run()
require.NoError(t, err)
require.NotContains(t, buf.String(), "Your license expires")
})
}