Skip to content

Commit

Permalink
TER-235: Add helpers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Caussat committed Mar 23, 2018
1 parent d9fb59c commit 3c69676
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions ghost/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package ghost

import (
"reflect"
"testing"
)

func TestStrToB64(t *testing.T) {
cases := []struct {
Input string
ExpectedOutput string
}{
{"mystring", "bXlzdHJpbmc="},
{"", ""},
}

for _, tc := range cases {
output := StrToB64(tc.Input)
if !reflect.DeepEqual(output, tc.ExpectedOutput) {
t.Fatalf("Unexpected output from StrToB64.\nExpected: %#v\nGiven: %#v",
tc.ExpectedOutput, output)
}
}
}

func TestB64ToStr(t *testing.T) {
cases := []struct {
Input string
ExpectedOutput string
}{
{"bXlzdHJpbmc=", "mystring"},
{"", ""},
}

for _, tc := range cases {
output := B64ToStr(tc.Input)
if !reflect.DeepEqual(output, tc.ExpectedOutput) {
t.Fatalf("Unexpected output from B64ToStr.\nExpected: %#v\nGiven: %#v",
tc.ExpectedOutput, output)
}
}
}

func TestMatchesRegexp(t *testing.T) {
cases := []struct {
Function func(v interface{}, k string) (ws []string, errors []error)
Value string
Valid bool
}{
{MatchesRegexp(`^[a-zA-Z0-9]*$`), "thisIsAPositiveTest", true},
{MatchesRegexp(`^[a-zA-Z0-9]*$`), "thisIsANegativeTest-", false},
}

for _, tc := range cases {
_, err := tc.Function(tc.Value, tc.Value)
if (tc.Valid && (err != nil)) || (!tc.Valid && (err == nil)) {
t.Fatalf("Unexpected output from MatchesRegexp: %v", err)
}
}
}

0 comments on commit 3c69676

Please sign in to comment.