瀏覽代碼

add benchmark decrypt

zcool321@sina.com 6 年之前
父節點
當前提交
441afd2acc
共有 1 個文件被更改,包括 28 次插入0 次删除
  1. 28 0
      gtoken/gtoken_test.go

+ 28 - 0
gtoken/gtoken_test.go

@@ -30,3 +30,31 @@ func TestEncryptDecryptToken(t *testing.T) {
 	}
 
 }
+
+func BenchmarkEncryptDecryptToken(b *testing.B) {
+	b.Log("encrypt and decrypt token test ")
+	gtoken := gtoken.GfToken{}
+	gtoken.Init()
+
+	userKey := "123123"
+	token := gtoken.EncryptToken(userKey)
+	if !token.Success() {
+		b.Error(token.Json())
+	}
+	b.Log(token.DataString())
+
+	for i := 0; i < b.N; i++ {
+		token2 := gtoken.DecryptToken(token.GetString("token"))
+		if !token2.Success() {
+			b.Error(token2.Json())
+		}
+		b.Log(token2.DataString())
+		if userKey != token2.GetString("userKey") {
+			b.Error("token decrypt userKey error")
+		}
+		if token.GetString("uuid") != token2.GetString("uuid") {
+			b.Error("token decrypt uuid error")
+		}
+	}
+
+}