From 145b52f34302a7d2d12e3113d88beb55a0f5c36a Mon Sep 17 00:00:00 2001 From: pibigstar Date: Sat, 6 Apr 2019 12:18:51 +0800 Subject: [PATCH] increase coverage for crypto #66 --- .../gcrc32/{gcr32_test.go => gcrc32_test.go} | 0 g/crypto/gmd5/gmd5_test.go | 21 ++++++++++++++++++- g/crypto/gsha1/gsha1_test.go | 6 +++++- 3 files changed, 25 insertions(+), 2 deletions(-) rename g/crypto/gcrc32/{gcr32_test.go => gcrc32_test.go} (100%) diff --git a/g/crypto/gcrc32/gcr32_test.go b/g/crypto/gcrc32/gcrc32_test.go similarity index 100% rename from g/crypto/gcrc32/gcr32_test.go rename to g/crypto/gcrc32/gcrc32_test.go diff --git a/g/crypto/gmd5/gmd5_test.go b/g/crypto/gmd5/gmd5_test.go index eaff5a2b1..7d40626f3 100644 --- a/g/crypto/gmd5/gmd5_test.go +++ b/g/crypto/gmd5/gmd5_test.go @@ -22,10 +22,29 @@ var ( result = "d175a1ff66aedde64344785f7f7a3df8" ) +type user struct { + name string + password string + age int +} + func TestEncrypt(t *testing.T) { gtest.Case(t, func() { encryptString := gmd5.Encrypt(s) gtest.Assert(encryptString, result) + + encrypt := gmd5.Encrypt(123456) + gtest.AssertNE(encrypt,"") + }) + + gtest.Case(t, func() { + user := &user{ + name: "派大星", + password: "123456", + age: 23, + } + encrypt := gmd5.Encrypt(user) + gtest.AssertNE(encrypt,"") }) } @@ -46,5 +65,5 @@ func TestEncryptFile(t *testing.T) { encryptFile := gmd5.EncryptFile(path) gtest.AssertNE(encryptFile, "") }) - os.Remove(path) + defer os.Remove(path) } diff --git a/g/crypto/gsha1/gsha1_test.go b/g/crypto/gsha1/gsha1_test.go index d53ae5265..bff462482 100644 --- a/g/crypto/gsha1/gsha1_test.go +++ b/g/crypto/gsha1/gsha1_test.go @@ -32,6 +32,10 @@ func TestEncrypt(t *testing.T) { encrypt := gsha1.Encrypt(user) gtest.AssertNE(encrypt, "") }) + gtest.Case(t, func() { + s := gsha1.Encrypt("pibigstar") + gtest.AssertNE(s, "") + }) } func TestEncryptString(t *testing.T) { @@ -51,5 +55,5 @@ func TestEncryptFile(t *testing.T) { encryptFile := gsha1.EncryptFile(path) gtest.AssertNE(encryptFile, "") }) - os.Remove(path) + defer os.Remove(path) }