mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2026-05-04 22:26:16 +02:00
a node's BGP peer settings while maintaining backwards support for the existing annotations to address #1393.
49 lines
942 B
Go
49 lines
942 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/goccy/go-yaml"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestBase64String(t *testing.T) {
|
|
type testStruct struct {
|
|
Password Base64String `yaml:"password"`
|
|
}
|
|
|
|
tcs := []struct {
|
|
name string
|
|
input []byte
|
|
shouldError bool
|
|
errorContains string
|
|
}{
|
|
{
|
|
name: "happy path",
|
|
// b64: hello world
|
|
input: []byte(`password: "aGVsbG8gd29ybGQ="`),
|
|
},
|
|
{
|
|
name: "invalid base64 encoding",
|
|
input: []byte(`password: "notbase64"`),
|
|
shouldError: true,
|
|
errorContains: "failed to base64 decode",
|
|
},
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
t.Run(tc.name, func(tt *testing.T) {
|
|
var ts testStruct
|
|
err := yaml.Unmarshal(tc.input, &ts)
|
|
fmt.Printf("TS: %+v\n", ts)
|
|
if tc.shouldError {
|
|
assert.ErrorContains(tt, err, tc.errorContains)
|
|
} else {
|
|
assert.NoError(tt, err)
|
|
assert.NotEmpty(tt, ts.Password)
|
|
}
|
|
})
|
|
}
|
|
}
|