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