Explorar el Código

添加base64测试

yjp hace 2 meses
padre
commit
e130aef8ed
Se han modificado 1 ficheros con 18 adiciones y 0 borrados
  1. 18 0
      encoding/encoding_test.go

+ 18 - 0
encoding/encoding_test.go

@@ -77,3 +77,21 @@ func TestSHA1(t *testing.T) {
 		t.Fatal("sha1字符串不正确")
 	}
 }
+
+func TestBase64(t *testing.T) {
+	origin := "foo"
+
+	encoded := Base64Encode([]byte(origin))
+	if encoded != "Zm9v" {
+		t.Fatal("base64加密失败")
+	}
+
+	decoded, err := Base64Decode(encoded)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if string(decoded) != origin {
+		t.Fatal("base64解密失败")
+	}
+}