(t *testing.T)
| 402 | } |
| 403 | |
| 404 | func TestStructExportData(t *testing.T) { |
| 405 | tf, _ := time.Parse(time.RFC3339, "2024-01-01T00:00:00Z") |
| 406 | type s struct { |
| 407 | StringField string |
| 408 | IntField int |
| 409 | BoolField bool |
| 410 | TimeField time.Time |
| 411 | SliceField []int |
| 412 | MapField map[string]int |
| 413 | StructField struct { |
| 414 | A string |
| 415 | B int |
| 416 | c bool |
| 417 | } |
| 418 | unexportedField int |
| 419 | } |
| 420 | export := s{ |
| 421 | StringField: "test", |
| 422 | IntField: 1, |
| 423 | BoolField: true, |
| 424 | TimeField: tf, |
| 425 | SliceField: []int{1, 2, 3}, |
| 426 | MapField: map[string]int{ |
| 427 | "one": 1, |
| 428 | "two": 2, |
| 429 | "three": 3, |
| 430 | }, |
| 431 | StructField: struct { |
| 432 | A string |
| 433 | B int |
| 434 | c bool |
| 435 | }{ |
| 436 | A: "a", |
| 437 | B: 1, |
| 438 | c: true, |
| 439 | }, |
| 440 | unexportedField: 4, |
| 441 | } |
| 442 | fields := []string{"stringField", "intField", "boolField", "sliceField", "mapField", "structField"} |
| 443 | tests := []struct { |
| 444 | name string |
| 445 | export interface{} |
| 446 | fields []string |
| 447 | wantOut string |
| 448 | }{ |
| 449 | { |
| 450 | name: "serializes struct types", |
| 451 | export: export, |
| 452 | fields: fields, |
| 453 | wantOut: `{"boolField":true,"intField":1,"mapField":{"one":1,"three":3,"two":2},"sliceField":[1,2,3],"stringField":"test","structField":{"A":"a","B":1}}`, |
| 454 | }, |
| 455 | { |
| 456 | name: "serializes pointer to struct types", |
| 457 | export: &export, |
| 458 | fields: fields, |
| 459 | wantOut: `{"boolField":true,"intField":1,"mapField":{"one":1,"three":3,"two":2},"sliceField":[1,2,3],"stringField":"test","structField":{"A":"a","B":1}}`, |
| 460 | }, |
| 461 | { |
nothing calls this directly
no test coverage detected