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

Function TestValidateChatLabels

coderd/httpapi/chatlabels_test.go:13–191  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestValidateChatLabels(t *testing.T) {
14 t.Parallel()
15
16 t.Run("NilMap", func(t *testing.T) {
17 t.Parallel()
18 errs := httpapi.ValidateChatLabels(nil)
19 require.Empty(t, errs)
20 })
21
22 t.Run("EmptyMap", func(t *testing.T) {
23 t.Parallel()
24 errs := httpapi.ValidateChatLabels(map[string]string{})
25 require.Empty(t, errs)
26 })
27
28 t.Run("ValidLabels", func(t *testing.T) {
29 t.Parallel()
30 labels := map[string]string{
31 "env": "production",
32 "github.repo": "coder/coder",
33 "automation/pr": "12345",
34 "team-backend": "core",
35 "version_number": "v1.2.3",
36 "A1.b2/c3-d4_e5": "mixed",
37 }
38 errs := httpapi.ValidateChatLabels(labels)
39 require.Empty(t, errs)
40 })
41
42 t.Run("TooManyLabels", func(t *testing.T) {
43 t.Parallel()
44 labels := make(map[string]string, 51)
45 for i := range 51 {
46 labels[strings.Repeat("k", i+1)] = "v"
47 }
48 errs := httpapi.ValidateChatLabels(labels)
49 require.NotEmpty(t, errs)
50
51 found := false
52 for _, e := range errs {
53 if strings.Contains(e.Detail, "too many labels") {
54 found = true
55 break
56 }
57 }
58 assert.True(t, found, "expected a 'too many labels' error")
59 })
60
61 t.Run("KeyTooLong", func(t *testing.T) {
62 t.Parallel()
63 longKey := strings.Repeat("a", 65)
64 labels := map[string]string{
65 longKey: "value",
66 }
67 errs := httpapi.ValidateChatLabels(labels)
68 require.NotEmpty(t, errs)
69
70 found := false

Callers

nothing calls this directly

Calls 7

ValidateChatLabelsFunction · 0.92
NotEmptyMethod · 0.80
RunMethod · 0.65
EmptyMethod · 0.45
ContainsMethod · 0.45
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected