diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2024-01-25 20:11:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-25 20:11:31 -0500 |
| commit | ebb97fb7367fb983cffc1935a8fb57e4b80f5249 (patch) | |
| tree | 43ef6cd01f629f60f59efe1e5b003f7c8e3a1257 /funcs/base64_test.go | |
| parent | f1d9158ea99abbe556251c1ff2fe970f3b460ee9 (diff) | |
Move funcs package to internal (#1977)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'funcs/base64_test.go')
| -rw-r--r-- | funcs/base64_test.go | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/funcs/base64_test.go b/funcs/base64_test.go deleted file mode 100644 index f0cca886..00000000 --- a/funcs/base64_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package funcs - -import ( - "bytes" - "context" - "strconv" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestCreateBase64Funcs(t *testing.T) { - t.Parallel() - - for i := 0; i < 10; i++ { - // Run this a bunch to catch race conditions - t.Run(strconv.Itoa(i), func(t *testing.T) { - t.Parallel() - - ctx := context.Background() - fmap := CreateBase64Funcs(ctx) - actual := fmap["base64"].(func() interface{}) - - assert.Equal(t, ctx, actual().(*Base64Funcs).ctx) - }) - } -} - -func TestBase64Encode(t *testing.T) { - t.Parallel() - - bf := &Base64Funcs{} - assert.Equal(t, "Zm9vYmFy", must(bf.Encode("foobar"))) -} - -func TestBase64Decode(t *testing.T) { - t.Parallel() - - bf := &Base64Funcs{} - assert.Equal(t, "foobar", must(bf.Decode("Zm9vYmFy"))) -} - -func TestBase64DecodeBytes(t *testing.T) { - t.Parallel() - - bf := &Base64Funcs{} - out, err := bf.DecodeBytes("Zm9vYmFy") - require.NoError(t, err) - assert.Equal(t, "foobar", string(out)) -} - -func TestToBytes(t *testing.T) { - t.Parallel() - - assert.Equal(t, []byte{0, 1, 2, 3}, toBytes([]byte{0, 1, 2, 3})) - - buf := &bytes.Buffer{} - buf.WriteString("hi") - assert.Equal(t, []byte("hi"), toBytes(buf)) - assert.Equal(t, []byte{}, toBytes(nil)) - assert.Equal(t, []byte("42"), toBytes(42)) -} - -func BenchmarkToBytes(b *testing.B) { - for i := 0; i < b.N; i++ { - b.StopTimer() - buf := &bytes.Buffer{} - buf.WriteString("hi") - bin := []byte{0, 1, 2, 3} - b.StartTimer() - - toBytes(bin) - - toBytes(buf) - toBytes(nil) - toBytes(42) - } -} |
