github.com/Venafi/vcert/v5@v5.10.2/pkg/certificate/customFieldType_test.go (about) 1 package certificate 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/suite" 7 ) 8 9 type CustomFieldTypeSuite struct { 10 suite.Suite 11 testYaml string 12 testCases []struct { 13 customFieldType CustomFieldType 14 strValue string 15 vcertValue CustomFieldType 16 } 17 } 18 19 func (s *CustomFieldTypeSuite) SetupTest() { 20 s.testCases = []struct { 21 customFieldType CustomFieldType 22 strValue string 23 vcertValue CustomFieldType 24 }{ 25 {customFieldType: CustomFieldPlain, strValue: strCFTypePlain}, 26 {customFieldType: CustomFieldOrigin, strValue: strCFTypeOrigin}, 27 {customFieldType: CustomFieldUnknown, strValue: strCFTypeUnknown}, 28 } 29 30 s.testYaml = `--- 31 name: foo 32 value: 123 33 ` 34 } 35 36 func TestCustomFieldType(t *testing.T) { 37 suite.Run(t, new(CustomFieldTypeSuite)) 38 } 39 40 func (s *CustomFieldTypeSuite) TestCustomFieldType_MarshalYAML() { 41 for _, tc := range s.testCases { 42 s.Run(tc.strValue, func() { 43 data, err := tc.customFieldType.MarshalYAML() 44 s.Nil(err) 45 s.Equal(tc.strValue, data.(string)) 46 }) 47 } 48 } 49 50 func (s *CustomFieldTypeSuite) TestCustomFieldType_String() { 51 for _, tc := range s.testCases { 52 s.Run(tc.strValue, func() { 53 str := tc.customFieldType.String() 54 s.Equal(tc.strValue, str) 55 }) 56 } 57 }