forked from claranet/terraform-provider-clouddeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Jordan Caussat
committed
Mar 23, 2018
1 parent
d9fb59c
commit 3c69676
Showing
1 changed file
with
60 additions
and
0 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
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) | ||
} | ||
} | ||
} |