| 1 | package base64url |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "fmt" |
| 6 | . "gopkg.in/check.v1" |
| 7 | ) |
| 8 | |
| 9 | func Test(t *testing.T) { TestingT(t) } |
| 10 | type TestSuite struct{} |
| 11 | var _ = Suite(&TestSuite{}) |
| 12 | |
| 13 | func (s *TestSuite) TestEncode(c *C) { |
| 14 | //given |
| 15 | in:=[]byte{72,101,108,108,111,32,66,97,115,101,54,52,85,114,108,32,101,110,99,111,100,105,110,103,33} |
| 16 | |
| 17 | //when |
| 18 | test:=Encode(in) |
| 19 | |
| 20 | //then |
| 21 | c.Assert(test, Equals, "SGVsbG8gQmFzZTY0VXJsIGVuY29kaW5nIQ") |
| 22 | } |
| 23 | |
| 24 | func (s *TestSuite) TestDecode(c *C) { |
| 25 | //when |
| 26 | test,err := Decode("SGVsbG8gQmFzZTY0VXJsIGVuY29kaW5nIQ") |
| 27 | |
| 28 | //then |
| 29 | c.Assert(err, IsNil) |
| 30 | c.Assert(test, DeepEquals, []byte{72,101,108,108,111,32,66,97,115,101,54,52,85,114,108,32,101,110,99,111,100,105,110,103,33}) |
| 31 | } |
| 32 | |
| 33 | func (s *TestSuite) TestDecodeIllegalBase64String(c *C) { |
| 34 | //when |
| 35 | _,err := Decode("SGVsbG8gQmFzZTY0VXJsIGVuY29kaW5nQ") |
| 36 | |
| 37 | //then |
| 38 | c.Assert(err,NotNil) |
| 39 | fmt.Printf("err = %v\n",err) |
| 40 | } |