(t *testing.T)
| 547 | } |
| 548 | |
| 549 | func TestDecodeAttribute(t *testing.T) { |
| 550 | for _, test := range decodeAttributeTestCases { |
| 551 | t.Run(test.name, func(t *testing.T) { |
| 552 | json := apiext.JSON{} |
| 553 | if err := json.UnmarshalJSON([]byte(test.attributeJson)); err != nil { |
| 554 | // This should never happen |
| 555 | panic(err) |
| 556 | } |
| 557 | |
| 558 | attributes := Attributes{ |
| 559 | "test": json, |
| 560 | } |
| 561 | |
| 562 | var err error = nil |
| 563 | assert.Equal(t, test.expectedBool, attributes.GetBoolean(test.attributeKey, &err)) |
| 564 | checkError(t, err, test.expectedBoolError) |
| 565 | |
| 566 | err = nil |
| 567 | assert.Equal(t, test.expectedString, attributes.GetString(test.attributeKey, &err)) |
| 568 | checkError(t, err, test.expectedStringError) |
| 569 | |
| 570 | err = nil |
| 571 | assert.Equal(t, test.expectedNumber, attributes.GetNumber(test.attributeKey, &err)) |
| 572 | checkError(t, err, test.expectedNumberError) |
| 573 | |
| 574 | err = nil |
| 575 | assert.Equal(t, test.expectedInterface, attributes.Get(test.attributeKey, &err)) |
| 576 | checkError(t, err, test.expectedInterfaceError) |
| 577 | |
| 578 | err = attributes.GetInto(test.attributeKey, test.decodeInto) |
| 579 | checkError(t, err, test.decodeIntoError) |
| 580 | |
| 581 | decodedValue := reflect.ValueOf(test.decodeInto) |
| 582 | if decodedValue.Kind() == reflect.Ptr { |
| 583 | decodedValue = decodedValue.Elem() |
| 584 | } |
| 585 | assert.Equal(t, test.decodeIntoExpectedValue, decodedValue.Interface()) |
| 586 | }) |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | type decodeAttributesTestCase struct { |
| 591 | name string |
nothing calls this directly
no test coverage detected