MCPcopy Index your code
hub / github.com/coder/coder / TestUserSecretNameValid

Function TestUserSecretNameValid

codersdk/usersecretvalidation_test.go:12–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestUserSecretNameValid(t *testing.T) {
13 t.Parallel()
14
15 tests := []struct {
16 name string
17 input string
18 wantErr bool
19 errMsg string
20 }{
21 {name: "Simple", input: "github-token"},
22 {name: "WithUnderscore", input: "github_token"},
23 {name: "WithDot", input: "github.token"},
24 {name: "Empty", input: "", wantErr: true, errMsg: "required"},
25 {name: "WhitespaceOnly", input: " ", wantErr: true, errMsg: "required"},
26 {name: "LeadingWhitespace", input: " github", wantErr: true, errMsg: "whitespace"},
27 {name: "TrailingWhitespace", input: "github ", wantErr: true, errMsg: "whitespace"},
28 {name: "Slash", input: "foo/bar", wantErr: true, errMsg: "must not contain"},
29 {name: "Question", input: "foo?bar", wantErr: true, errMsg: "must not contain"},
30 {name: "Fragment", input: "foo#bar", wantErr: true, errMsg: "must not contain"},
31 }
32
33 for _, tt := range tests {
34 t.Run(tt.name, func(t *testing.T) {
35 t.Parallel()
36 err := codersdk.UserSecretNameValid(tt.input)
37 if tt.wantErr {
38 assert.Error(t, err)
39 if tt.errMsg != "" {
40 assert.Contains(t, err.Error(), tt.errMsg)
41 }
42 } else {
43 assert.NoError(t, err)
44 }
45 })
46 }
47}
48
49func TestUserSecretEnvNameValid(t *testing.T) {
50 t.Parallel()

Callers

nothing calls this directly

Calls 4

UserSecretNameValidFunction · 0.92
RunMethod · 0.65
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected