|
4 | 4 | "bytes" |
5 | 5 | "database/sql" |
6 | 6 | "database/sql/driver" |
| 7 | + "encoding/json" |
7 | 8 | "fmt" |
8 | 9 | "reflect" |
9 | 10 | "testing" |
@@ -210,6 +211,42 @@ func TestNullableUniqueIdentifierUnmarshalJSONNull(t *testing.T) { |
210 | 211 | } |
211 | 212 | } |
212 | 213 |
|
213 | | -var _ fmt.Stringer = NullUniqueIdentifier{} |
214 | | -var _ sql.Scanner = &NullUniqueIdentifier{} |
215 | | -var _ driver.Valuer = NullUniqueIdentifier{} |
| 214 | +func TestNullableUniqueIdentifierMarshalJSONNull(t *testing.T) { |
| 215 | + t.Parallel() |
| 216 | + nullUUID := NullUniqueIdentifier{ |
| 217 | + UUID: [16]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, |
| 218 | + Valid: false, |
| 219 | + } |
| 220 | + |
| 221 | + got, err := nullUUID.MarshalJSON() |
| 222 | + if err != nil { |
| 223 | + t.Fatal(err) |
| 224 | + } |
| 225 | + want := []byte{0x6e, 0x75, 0x6c, 0x6c} // null = %x6e.75.6c.6c |
| 226 | + if !reflect.DeepEqual(got, want) { |
| 227 | + t.Errorf("got %v; want %v", got, want) |
| 228 | + } |
| 229 | +} |
| 230 | + |
| 231 | +func TestNullableUniqueIdentifierJSONMarshalNull(t *testing.T) { |
| 232 | + t.Parallel() |
| 233 | + nullUUID := NullUniqueIdentifier{ |
| 234 | + UUID: [16]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, |
| 235 | + Valid: false, |
| 236 | + } |
| 237 | + |
| 238 | + got, err := json.Marshal(nullUUID) |
| 239 | + if err != nil { |
| 240 | + t.Fatal(err) |
| 241 | + } |
| 242 | + want := []byte{0x6e, 0x75, 0x6c, 0x6c} |
| 243 | + if !reflect.DeepEqual(got, want) { |
| 244 | + t.Errorf("got %v; want %v", got, want) |
| 245 | + } |
| 246 | +} |
| 247 | + |
| 248 | +var ( |
| 249 | + _ fmt.Stringer = NullUniqueIdentifier{} |
| 250 | + _ sql.Scanner = &NullUniqueIdentifier{} |
| 251 | + _ driver.Valuer = NullUniqueIdentifier{} |
| 252 | +) |
0 commit comments