2022-01-20 07:46:51 -06:00
|
|
|
package coderdtest_test
|
|
|
|
|
|
|
|
|
|
import (
|
2026-01-09 15:40:26 -07:00
|
|
|
"strings"
|
2022-01-20 07:46:51 -06:00
|
|
|
"testing"
|
2026-01-09 15:40:26 -07:00
|
|
|
"unicode"
|
2022-01-20 07:46:51 -06:00
|
|
|
|
2026-01-09 15:40:26 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-01-20 07:46:51 -06:00
|
|
|
"go.uber.org/goleak"
|
|
|
|
|
|
2023-08-18 13:55:43 -05:00
|
|
|
"github.com/coder/coder/v2/coderd/coderdtest"
|
2025-01-08 15:38:37 +00:00
|
|
|
"github.com/coder/coder/v2/testutil"
|
2022-01-20 07:46:51 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2025-01-08 15:38:37 +00:00
|
|
|
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
|
2022-01-20 07:46:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestNew(t *testing.T) {
|
2022-01-24 11:07:42 -06:00
|
|
|
t.Parallel()
|
2022-06-27 13:50:52 -05:00
|
|
|
client := coderdtest.New(t, &coderdtest.Options{
|
2022-09-04 11:28:09 -05:00
|
|
|
IncludeProvisionerDaemon: true,
|
2022-06-27 13:50:52 -05:00
|
|
|
})
|
2022-03-07 11:40:54 -06:00
|
|
|
user := coderdtest.CreateFirstUser(t, client)
|
2022-04-06 12:42:40 -05:00
|
|
|
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
2023-10-03 11:02:56 -06:00
|
|
|
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
|
2022-04-06 12:42:40 -05:00
|
|
|
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
|
2024-07-30 10:44:02 -06:00
|
|
|
workspace := coderdtest.CreateWorkspace(t, client, template.ID)
|
2023-10-03 11:02:56 -06:00
|
|
|
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
|
2022-10-03 17:01:13 -04:00
|
|
|
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
|
2022-03-25 13:48:08 -06:00
|
|
|
_, _ = coderdtest.NewGoogleInstanceIdentity(t, "example", false)
|
2022-03-28 13:31:03 -06:00
|
|
|
_, _ = coderdtest.NewAWSInstanceIdentity(t, "an-instance")
|
2022-01-20 07:46:51 -06:00
|
|
|
}
|
2026-01-09 15:40:26 -07:00
|
|
|
|
|
|
|
|
func TestRandomName(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
for range 10 {
|
|
|
|
|
name := coderdtest.RandomName(t)
|
|
|
|
|
|
|
|
|
|
require.NotEmpty(t, name, "name should not be empty")
|
|
|
|
|
require.NotContains(t, name, "_", "name should not contain underscores")
|
|
|
|
|
|
|
|
|
|
// Should be title cased (e.g., "Happy Einstein").
|
|
|
|
|
words := strings.Split(name, " ")
|
|
|
|
|
require.Len(t, words, 2, "name should have exactly two words")
|
|
|
|
|
for _, word := range words {
|
|
|
|
|
firstRune := []rune(word)[0]
|
|
|
|
|
require.True(t, unicode.IsUpper(firstRune), "word %q should start with uppercase letter", word)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|