MCPcopy Create free account
hub / github.com/devfile/api / TestDecodeAttribute

Function TestDecodeAttribute

pkg/attributes/attributes_test.go:549–588  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

547}
548
549func 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
590type decodeAttributesTestCase struct {
591 name string

Callers

nothing calls this directly

Calls 7

GetBooleanMethod · 0.95
GetStringMethod · 0.95
GetNumberMethod · 0.95
GetMethod · 0.95
GetIntoMethod · 0.95
checkErrorFunction · 0.85
UnmarshalJSONMethod · 0.80

Tested by

no test coverage detected