File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ package utils
2+
3+ import (
4+ "fmt"
5+ "testing"
6+
7+ "github.com/goccy/go-yaml"
8+ "github.com/stretchr/testify/assert"
9+ )
10+
11+ func TestBase64String (t * testing.T ) {
12+ type testStruct struct {
13+ Password Base64String `yaml:"password"`
14+ }
15+
16+ tcs := []struct {
17+ name string
18+ input []byte
19+ shouldError bool
20+ errorContains string
21+ }{
22+ {
23+ name : "happy path" ,
24+ // b64: hello world
25+ input : []byte (`password: "aGVsbG8gd29ybGQ="` ),
26+ },
27+ {
28+ name : "invalid base64 encoding" ,
29+ input : []byte (`password: "notbase64"` ),
30+ shouldError : true ,
31+ errorContains : "failed to base64 decode" ,
32+ },
33+ }
34+
35+ for _ , tc := range tcs {
36+ t .Run (tc .name , func (tt * testing.T ) {
37+ var ts testStruct
38+ err := yaml .Unmarshal (tc .input , & ts )
39+ fmt .Printf ("TS: %+v\n " , ts )
40+ if tc .shouldError {
41+ assert .ErrorContains (tt , err , tc .errorContains )
42+ } else {
43+ assert .NoError (tt , err )
44+ assert .NotEmpty (tt , ts .Password )
45+ }
46+ })
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments