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

Function TestUserSkillValidationAndConflicts

coderd/userskills_test.go:114–206  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestUserSkillValidationAndConflicts(t *testing.T) {
115 t.Parallel()
116
117 adminClient := coderdtest.New(t, nil)
118 firstUser := coderdtest.CreateFirstUser(t, adminClient)
119 ownerClient, _ := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID)
120 otherClient, _ := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID)
121 owner := codersdk.NewExperimentalClient(ownerClient)
122 other := codersdk.NewExperimentalClient(otherClient)
123
124 tests := []struct {
125 name string
126 content string
127 expectedMessage string
128 }{
129 {
130 name: "MissingFrontmatterDelimiters",
131 content: "name: missing-frontmatter\n\nBody.",
132 expectedMessage: "Invalid skill content.",
133 },
134 {
135 name: "MissingName",
136 content: "---\n" +
137 "description: Missing name\n" +
138 "---\n\nBody.",
139 expectedMessage: "Invalid skill name.",
140 },
141 {
142 name: "NonKebabCaseName",
143 content: userSkillMarkdown("NotKebab", "Invalid", "Body."),
144 expectedMessage: "Invalid skill name.",
145 },
146 {
147 name: "NameTooLong",
148 content: userSkillMarkdown(strings.Repeat("a", skills.MaxPersonalSkillNameBytes+1), "Invalid", "Body."),
149 expectedMessage: "Invalid skill name.",
150 },
151 {
152 name: "EmptyBody",
153 content: userSkillMarkdown("empty-body", "Invalid", " \n"),
154 expectedMessage: "Skill body is required.",
155 },
156 {
157 name: "TooLarge",
158 content: strings.Repeat("a", skills.MaxPersonalSkillSizeBytes+1),
159 expectedMessage: "Skill content is too large.",
160 },
161 }
162 for _, tt := range tests {
163 t.Run(tt.name, func(t *testing.T) {
164 t.Parallel()
165
166 subCtx := testutil.Context(t, testutil.WaitMedium)
167 _, err := owner.CreateUserSkill(subCtx, codersdk.Me, codersdk.CreateUserSkillRequest{Content: tt.content})
168 sdkErr := requireSDKErrorStatus(t, err, http.StatusBadRequest)
169 assert.Equal(t, tt.expectedMessage, sdkErr.Message)
170 })
171 }

Callers

nothing calls this directly

Calls 11

CreateUserSkillMethod · 0.95
UpdateUserSkillMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
NewExperimentalClientFunction · 0.92
ContextFunction · 0.92
requireSDKErrorStatusFunction · 0.85
userSkillMarkdownFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected