config: add NameRegexp
This commit is contained in:
parent
c7088eb82a
commit
50e5eacc15
|
@ -4,6 +4,7 @@ package config
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -13,6 +14,10 @@ import (
|
|||
"github.com/mitchellh/reflectwalk"
|
||||
)
|
||||
|
||||
// NameRegexp is the regular expression that all names (modules, providers,
|
||||
// resources, etc.) must follow.
|
||||
var NameRegexp = regexp.MustCompile(`\A[A-Za-z0-9\-\_]+\z`)
|
||||
|
||||
// Config is the configuration that comes from loading a collection
|
||||
// of Terraform templates.
|
||||
type Config struct {
|
||||
|
|
|
@ -228,6 +228,26 @@ func TestConfigValidate_varModuleInvalid(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNameRegexp(t *testing.T) {
|
||||
cases := []struct{
|
||||
Input string
|
||||
Match bool
|
||||
}{
|
||||
{"hello", true},
|
||||
{"foo-bar", true},
|
||||
{"foo_bar", true},
|
||||
{"_hello", true},
|
||||
{"foo bar", false},
|
||||
{"foo.bar", false},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
if NameRegexp.Match([]byte(tc.Input)) != tc.Match {
|
||||
t.Fatalf("Input: %s\n\nExpected: %#v", tc.Input, tc.Match)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderConfigName(t *testing.T) {
|
||||
pcs := []*ProviderConfig{
|
||||
&ProviderConfig{Name: "aw"},
|
||||
|
|
Loading…
Reference in New Issue