github.com/lestrrat-go/jwx/v2@v2.0.21/internal/base64/base64_test.go (about) 1 package base64 2 3 import ( 4 "encoding/base64" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestDecode(t *testing.T) { 11 testcases := []struct { 12 Name string 13 Encoding *base64.Encoding 14 }{ 15 { 16 Name: "base64.RawURLEncoding", 17 Encoding: base64.RawURLEncoding, 18 }, 19 { 20 Name: "base64.URLEncoding", 21 Encoding: base64.URLEncoding, 22 }, 23 { 24 Name: "base64.RawStdEncoding", 25 Encoding: base64.RawStdEncoding, 26 }, 27 { 28 Name: "base64.StdEncoding", 29 Encoding: base64.StdEncoding, 30 }, 31 } 32 33 var payload = []byte("Hello, World") 34 for _, tc := range testcases { 35 tc := tc 36 t.Run(tc.Name, func(t *testing.T) { 37 dst := make([]byte, tc.Encoding.EncodedLen(len(payload))) 38 tc.Encoding.Encode(dst, payload) 39 40 decoded, err := Decode(dst) 41 if !assert.NoError(t, err, `Decode should succeed`) { 42 return 43 } 44 if !assert.Equal(t, payload, decoded, `decoded content should match`) { 45 return 46 } 47 }) 48 } 49 }