Skip to content

Commit

Permalink
Merge pull request #3 from Vaishnavij/testChanges
Browse files Browse the repository at this point in the history
Updating the tests to verify the generated string
  • Loading branch information
chr4 authored Dec 21, 2018
2 parents 999d519 + a0d4e1f commit f45081e
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion pwgen_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package pwgen

import "testing"
import (
"strings"
"testing"
)

func TestNew(t *testing.T) {
var password string
Expand All @@ -10,6 +13,9 @@ func TestNew(t *testing.T) {
t.Errorf("Expected length %d, got %d\n", i, len(password))
}
}
if !verifyGeneratedPassword(password, "ab") {
t.Errorf("Expected string to contain only {%s}, but got %s\n", alpha, password)
}
}

func TestNum(t *testing.T) {
Expand All @@ -20,6 +26,9 @@ func TestNum(t *testing.T) {
t.Errorf("Expected length %d, got %d\n", i, len(password))
}
}
if !verifyGeneratedPassword(password, num) {
t.Errorf("Expected string to contain only {%s}, but got %s\n", num, password)
}
}

func TestAlpha(t *testing.T) {
Expand All @@ -30,6 +39,9 @@ func TestAlpha(t *testing.T) {
t.Errorf("Expected length %d, got %d\n", i, len(password))
}
}
if !verifyGeneratedPassword(password, alpha) {
t.Errorf("Expected string to contain only {%s}, but got %s\n", alpha, password)
}
}

func TestSymbols(t *testing.T) {
Expand All @@ -40,6 +52,9 @@ func TestSymbols(t *testing.T) {
t.Errorf("Expected length %d, got %d\n", i, len(password))
}
}
if !verifyGeneratedPassword(password, symbols) {
t.Errorf("Expected string to contain only {%s}, but got %s\n", symbols, password)
}
}

func TestAlphaNum(t *testing.T) {
Expand All @@ -50,6 +65,9 @@ func TestAlphaNum(t *testing.T) {
t.Errorf("Expected length %d, got %d\n", i, len(password))
}
}
if !verifyGeneratedPassword(password, alphaNum) {
t.Errorf("Expected string to contain only {%s}, but got %s\n", alphaNum, password)
}
}

func TestAlphaNumSymbols(t *testing.T) {
Expand All @@ -60,4 +78,16 @@ func TestAlphaNumSymbols(t *testing.T) {
t.Errorf("Expected length %d, got %d\n", i, len(password))
}
}
if !verifyGeneratedPassword(password, alphaNumSymbols) {
t.Errorf("Expected string to contain only {%s}, but got %s\n", alphaNumSymbols, password)
}
}

func verifyGeneratedPassword(generatedString string, format string) bool {
for _, char := range generatedString {
if !strings.Contains(format, strings.ToLower(string(char))) {
return false
}
}
return true
}

0 comments on commit f45081e

Please sign in to comment.