-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package service | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestToBase64(t *testing.T) { | ||
|
||
tests := []struct { | ||
expected string | ||
word string | ||
}{ | ||
{"dGVzdGluZw", "testing"}, | ||
{"dGVzdA", "test"}, | ||
{"cGlnZ3ktYmFuaw", "piggy-bank"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
decoded := []byte(tt.word) | ||
|
||
encoded := toBase64(decoded) | ||
|
||
if encoded != tt.expected { | ||
t.Errorf("Expected %s, but got %s", tt.expected, encoded) | ||
} | ||
} | ||
|
||
} | ||
|
||
func TestFromBase64(t *testing.T) { | ||
tests := []struct { | ||
encoded string | ||
expected string | ||
}{ | ||
{"dGVzdGluZw", "testing"}, | ||
{"dGVzdA", "test"}, | ||
{"cGlnZ3ktYmFuaw", "piggy-bank"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
encoded := tt.encoded | ||
|
||
decoded, err := fromBase64(encoded) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if string(decoded) != tt.expected { | ||
t.Errorf("Expected %s, but got %s", tt.expected, decoded) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package service | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type TB struct { | ||
name string | ||
expected string | ||
actual string | ||
} | ||
|
||
func TestGeneratePass(t *testing.T) { | ||
secret := generatePass() | ||
secret2 := generatePass() | ||
|
||
if len(secret) != 43 { | ||
t.Errorf("Secret is not 32 bytes") | ||
} | ||
|
||
if secret == secret2 { | ||
t.Errorf("Secrets are the same.") | ||
} | ||
|
||
} |