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.
Merged in TER-235-add-create-ghost-app-feature (pull request #3)
TER-235 add create ghost app feature Approved-by: Jordan Caussat <[email protected]> Approved-by: Patrick Decat <[email protected]> Approved-by: Jérôme Respaut <[email protected]>
- Loading branch information
Showing
14 changed files
with
1,351 additions
and
136 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
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,27 @@ | ||
package ghost | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
func StrToB64(data string) string { | ||
return base64.StdEncoding.EncodeToString([]byte(data)) | ||
} | ||
|
||
func B64ToStr(data string) string { | ||
str, _ := base64.StdEncoding.DecodeString(data) | ||
|
||
return string(str) | ||
} | ||
|
||
func MatchesRegexp(exp string) func(v interface{}, k string) (ws []string, errors []error) { | ||
return func(v interface{}, k string) (ws []string, errors []error) { | ||
value := v.(string) | ||
if !regexp.MustCompile(exp).MatchString(value) { | ||
errors = append(errors, fmt.Errorf("%q must match %s", k, exp)) | ||
} | ||
return | ||
} | ||
} |
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,62 @@ | ||
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"}, | ||
{"", ""}, | ||
{"-1", ""}, | ||
{"()", ""}, | ||
} | ||
|
||
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) | ||
} | ||
} | ||
} |
Oops, something went wrong.