github.com/hairyhenderson/templater@v3.5.0+incompatible/base64/base64_test.go (about)

     1  package base64
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func must(r interface{}, err error) interface{} {
    10  	if err != nil {
    11  		return err
    12  	}
    13  	return r
    14  }
    15  
    16  func TestEncode(t *testing.T) {
    17  	assert.Equal(t, "", must(Encode([]byte(""))))
    18  	assert.Equal(t, "Zg==", must(Encode([]byte("f"))))
    19  	assert.Equal(t, "Zm8=", must(Encode([]byte("fo"))))
    20  	assert.Equal(t, "Zm9v", must(Encode([]byte("foo"))))
    21  	assert.Equal(t, "Zm9vYg==", must(Encode([]byte("foob"))))
    22  	assert.Equal(t, "Zm9vYmE=", must(Encode([]byte("fooba"))))
    23  	assert.Equal(t, "Zm9vYmFy", must(Encode([]byte("foobar"))))
    24  	assert.Equal(t, "A+B/", must(Encode([]byte{0x03, 0xe0, 0x7f})))
    25  }
    26  
    27  func TestDecode(t *testing.T) {
    28  	assert.Equal(t, []byte(""), must(Decode("")))
    29  	assert.Equal(t, []byte("f"), must(Decode("Zg==")))
    30  	assert.Equal(t, []byte("fo"), must(Decode("Zm8=")))
    31  	assert.Equal(t, []byte("foo"), must(Decode("Zm9v")))
    32  	assert.Equal(t, []byte("foob"), must(Decode("Zm9vYg==")))
    33  	assert.Equal(t, []byte("fooba"), must(Decode("Zm9vYmE=")))
    34  	assert.Equal(t, []byte("foobar"), must(Decode("Zm9vYmFy")))
    35  	assert.Equal(t, []byte{0x03, 0xe0, 0x7f}, must(Decode("A+B/")))
    36  	assert.Equal(t, []byte{0x03, 0xe0, 0x7f}, must(Decode("A-B_")))
    37  
    38  	_, err := Decode("b.o.g.u.s")
    39  	assert.Error(t, err)
    40  }