-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactoring] Devspace Controller (#2182)
* ♻️ (DevSpace) Follow up Tom's suggestions on PR#2086 Add more validations and nil check in devspace. * Fix the format issue of devspace controller. * Fix the TestBase64String issue. * Simplify the error message for flattening sku. Co-Authored-By: metacpp <1684739+metacpp@users.noreply.github.com> * Update documentation for name of sku. Co-Authored-By: metacpp <1684739+metacpp@users.noreply.github.com> * Update the documentation for tier Co-Authored-By: metacpp <1684739+metacpp@users.noreply.github.com> * add `'s` Co-Authored-By: metacpp <1684739+metacpp@users.noreply.github.com> * Simplify the code to set controller property fields. * Fixing the formatting
- Loading branch information
1 parent
a4241b0
commit 206ff8a
Showing
4 changed files
with
87 additions
and
25 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,30 @@ | ||
package validate | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
) | ||
|
||
func Base64String() schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) (s []string, es []error) { | ||
// Empty string is not allowed | ||
if s, es = validation.NoZeroValues(i, k); len(es) > 0 { | ||
return | ||
} | ||
|
||
v, ok := i.(string) | ||
if !ok { | ||
es = append(es, fmt.Errorf("expected type of %s to be string", k)) | ||
return | ||
} | ||
|
||
if _, err := base64.StdEncoding.DecodeString(v); err != nil { | ||
es = append(es, fmt.Errorf("expect value (%s) of %s is base64 string", v, k)) | ||
} | ||
|
||
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,35 @@ | ||
package validate | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestBase64String(t *testing.T) { | ||
cases := []struct { | ||
Input string | ||
Errors int | ||
}{ | ||
{ | ||
Input: "", | ||
Errors: 1, | ||
}, | ||
{ | ||
Input: "aGVsbG8td29ybGQ=", | ||
Errors: 0, | ||
}, | ||
{ | ||
Input: "hello-world", | ||
Errors: 1, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.Input, func(t *testing.T) { | ||
_, errors := Base64String()(tc.Input, "base64") | ||
|
||
if len(errors) != tc.Errors { | ||
t.Fatalf("Expected Base64 string to have %d not %d errors for %q: %v", tc.Errors, len(errors), tc.Input, errors) | ||
} | ||
}) | ||
} | ||
} |
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