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

Function TestParseUUIDList

coderd/util/xjson/xjson_test.go:12–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestParseUUIDList(t *testing.T) {
13 t.Parallel()
14
15 a := uuid.MustParse("c7c6686d-a93c-4df2-bef9-5f837e9a33d5")
16 b := uuid.MustParse("8f3b3e0b-2c3f-46a5-a365-fd5b62bd8818")
17
18 tests := []struct {
19 name string
20 input string
21 want []uuid.UUID
22 wantErr string
23 }{
24 {
25 name: "EmptyString",
26 input: "",
27 want: []uuid.UUID{},
28 },
29 {
30 name: "JSONNull",
31 input: "null",
32 want: []uuid.UUID{},
33 },
34 {
35 name: "WhitespaceOnly",
36 input: " \n\t ",
37 want: []uuid.UUID{},
38 },
39 {
40 name: "ValidUUIDs",
41 input: `["c7c6686d-a93c-4df2-bef9-5f837e9a33d5","8f3b3e0b-2c3f-46a5-a365-fd5b62bd8818"]`,
42 want: []uuid.UUID{a, b},
43 },
44 {
45 name: "InvalidJSON",
46 input: "not json at all",
47 wantErr: "unmarshal uuid list",
48 },
49 {
50 name: "InvalidUUID",
51 input: `["not-a-uuid"]`,
52 wantErr: "parse uuid",
53 },
54 }
55
56 for _, tt := range tests {
57 t.Run(tt.name, func(t *testing.T) {
58 t.Parallel()
59 got, err := xjson.ParseUUIDList(tt.input)
60 if tt.wantErr != "" {
61 require.Error(t, err)
62 require.Contains(t, err.Error(), tt.wantErr)
63 return
64 }
65 require.NoError(t, err)
66 require.NotNil(t, got)
67 require.Equal(t, tt.want, got)
68 })
69 }

Callers

nothing calls this directly

Calls 5

ParseUUIDListFunction · 0.92
RunMethod · 0.65
ErrorMethod · 0.45
ContainsMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected