(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func 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 | |
| 49 | func TestUserSecretEnvNameValid(t *testing.T) { |
| 50 | t.Parallel() |
nothing calls this directly
no test coverage detected