2017-06-06 13:49:49 +00:00
|
|
|
package credsutil
|
|
|
|
|
|
|
|
import (
|
2017-07-17 18:51:27 +00:00
|
|
|
"strings"
|
2017-06-06 13:49:49 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-07-17 18:51:27 +00:00
|
|
|
func TestRandomAlphaNumeric(t *testing.T) {
|
2017-08-11 01:28:18 +00:00
|
|
|
s, err := RandomAlphaNumeric(10, true)
|
2017-06-06 13:49:49 +00:00
|
|
|
if err != nil {
|
2017-07-17 18:51:27 +00:00
|
|
|
t.Fatalf("Unexpected error: %s", err)
|
2017-06-06 13:49:49 +00:00
|
|
|
}
|
2017-07-17 18:51:27 +00:00
|
|
|
if len(s) != 10 {
|
|
|
|
t.Fatalf("Unexpected length of string, expected 10, got string: %s", s)
|
2017-06-06 13:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 01:28:18 +00:00
|
|
|
s, err = RandomAlphaNumeric(20, true)
|
2017-06-06 13:49:49 +00:00
|
|
|
if err != nil {
|
2017-07-17 18:51:27 +00:00
|
|
|
t.Fatalf("Unexpected error: %s", err)
|
2017-06-06 13:49:49 +00:00
|
|
|
}
|
2017-07-17 18:51:27 +00:00
|
|
|
if len(s) != 20 {
|
|
|
|
t.Fatalf("Unexpected length of string, expected 20, got string: %s", s)
|
2017-06-06 13:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 18:51:27 +00:00
|
|
|
if !strings.Contains(s, reqStr) {
|
|
|
|
t.Fatalf("Expected %s to contain %s", s, reqStr)
|
2017-06-06 13:49:49 +00:00
|
|
|
}
|
2017-08-11 01:28:18 +00:00
|
|
|
|
|
|
|
s, err = RandomAlphaNumeric(20, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
if len(s) != 20 {
|
|
|
|
t.Fatalf("Unexpected length of string, expected 20, got string: %s", s)
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.Contains(s, reqStr) {
|
|
|
|
t.Fatalf("Expected %s not to contain %s", s, reqStr)
|
|
|
|
}
|
2017-06-06 13:49:49 +00:00
|
|
|
}
|