Skip to content

Commit

Permalink
test: aiming for 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinaldy Rafli committed Jun 22, 2021
1 parent bb81927 commit a2c559d
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions phc-crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
phccrypto "github.com/aldy505/phc-crypto"
)

func TestPHCCrypto(t *testing.T) {
func TestPHCCrypto_Regular(t *testing.T) {
t.Run("setup test", func(t *testing.T) {
t.Run("should return the same name with input", func(t *testing.T) {
names := []string{"scrypt", "pbkdf2", "chacha20poly1305", "bcrypt", "argon2"}
Expand All @@ -28,6 +28,31 @@ func TestPHCCrypto(t *testing.T) {
}
})
})
t.Run("forced not supported algorithms", func(t *testing.T) {
t.Run("should return error on hash", func(t *testing.T) {
crypto := &phccrypto.Algo{
Name: "whatever",
Config: &phccrypto.Config{},
}
_, err := crypto.Hash("something")
if err.Error() != "the algorithm provided is not supported" {
t.Error("something is wrong:", crypto.Name, "with", err.Error())
}
})
t.Run("should return error on verify", func(t *testing.T) {
crypto := &phccrypto.Algo{
Name: "whatever",
Config: &phccrypto.Config{},
}
_, err := crypto.Verify("something else", "something")
if err.Error() != "the algorithm provided is not (yet) supported" {
t.Error("something is wrong:", crypto.Name, "with", err.Error())
}
})
})
}

func TestPHCCrypto_Scrypt(t *testing.T) {
t.Run("scrypt test", func(t *testing.T) {
t.Run("should be ok without additional config", func(t *testing.T) {
crypto, err := phccrypto.Use("scrypt", phccrypto.Config{})
Expand All @@ -51,7 +76,7 @@ func TestPHCCrypto(t *testing.T) {
t.Error(err)
}
hash, err := crypto.Hash("password123")
t.Log(hash)

if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -103,6 +128,9 @@ func TestPHCCrypto(t *testing.T) {
}
})
})
}

func TestPHCCrypto_Argon2(t *testing.T) {
t.Run("argon2 test", func(t *testing.T) {
t.Run("should be ok without additional config", func(t *testing.T) {
crypto, err := phccrypto.Use("argon2", phccrypto.Config{})
Expand All @@ -127,7 +155,7 @@ func TestPHCCrypto(t *testing.T) {
t.Error(err)
}
hash, err := crypto.Hash("password123")
t.Log(hash)

if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -179,6 +207,9 @@ func TestPHCCrypto(t *testing.T) {
}
})
})
}

func TestPHCCrypto_Bcrypt(t *testing.T) {
t.Run("bcrypt test", func(t *testing.T) {
t.Run("should be ok without additional config", func(t *testing.T) {
crypto, err := phccrypto.Use("bcrypt", phccrypto.Config{
Expand All @@ -188,7 +219,7 @@ func TestPHCCrypto(t *testing.T) {
t.Error(err)
}
hash, err := crypto.Hash("password123")
t.Log(hash)

if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -240,6 +271,9 @@ func TestPHCCrypto(t *testing.T) {
}
})
})
}

func TestPHCCrypto_PBKDF2(t *testing.T) {
t.Run("pbkdf2 test", func(t *testing.T) {
t.Run("should be ok without additional config", func(t *testing.T) {
crypto, err := phccrypto.Use("pbkdf2", phccrypto.Config{})
Expand All @@ -263,7 +297,6 @@ func TestPHCCrypto(t *testing.T) {
t.Error(err)
}
hash, err := crypto.Hash("password123")
t.Log(hash)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -315,14 +348,16 @@ func TestPHCCrypto(t *testing.T) {
}
})
})
}

func TestPHCCrypto_Chacha20poly1305(t *testing.T) {
t.Run("chacha20poly1305 test", func(t *testing.T) {
t.Run("should be ok without additional config", func(t *testing.T) {
crypto, err := phccrypto.Use("chacha20poly1305", phccrypto.Config{})
if err != nil {
t.Error(err)
}
hash, err := crypto.Hash("password123")
t.Log(hash)
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit a2c559d

Please sign in to comment.