Made changes to add support for cross-platform (os) testing as tests would pass on MacOS but no Windows

This commit is contained in:
Matthew E. Grahlman committed 2021-10-10 16:38:24 -04:00
1 parent d8e3a694f2
commit 36a4871585
1 file changed
+15 -15
+15 -15
View File
@@ -30,95 +30,95 @@ func TestParse(t *testing.T) {
{ {
description: "test successful load", description: "test successful load",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "aws_key.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "aws_key.toml")),
}, },
}, },
{ {
description: "test bad toml", description: "test bad toml",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_aws_key.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_aws_key.toml")),
}, },
wantErr: fmt.Errorf("Near line 7 (last key parsed 'rules.description'): expected value but found \"AWS\" instead"), wantErr: fmt.Errorf("Near line 7 (last key parsed 'rules.description'): expected value but found \"AWS\" instead"),
}, },
{ {
description: "test bad regex", description: "test bad regex",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_regex_aws_key.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_regex_aws_key.toml")),
}, },
wantErr: fmt.Errorf("problem loading config: error parsing regexp: invalid nested repetition operator: `???`"), wantErr: fmt.Errorf("problem loading config: error parsing regexp: invalid nested repetition operator: `???`"),
}, },
{ {
description: "test bad global allowlist file regex", description: "test bad global allowlist file regex",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_aws_key_global_allowlist_file.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_aws_key_global_allowlist_file.toml")),
}, },
wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"), wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"),
}, },
{ {
description: "test bad global file regex", description: "test bad global file regex",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_aws_key_file_regex.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_aws_key_file_regex.toml")),
}, },
wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"), wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"),
}, },
{ {
description: "test successful load big ol thing", description: "test successful load big ol thing",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "large.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "large.toml")),
}, },
}, },
{ {
description: "test load entropy", description: "test load entropy",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "entropy.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "entropy.toml")),
}, },
}, },
{ {
description: "test entropy bad range", description: "test entropy bad range",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_entropy_1.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_1.toml")),
}, },
wantErr: fmt.Errorf("problem loading config: entropy Min value cannot be higher than Max value"), wantErr: fmt.Errorf("problem loading config: entropy Min value cannot be higher than Max value"),
}, },
{ {
description: "test entropy value max", description: "test entropy value max",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_entropy_2.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_2.toml")),
}, },
wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"), wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"),
}, },
{ {
description: "test entropy value min", description: "test entropy value min",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_entropy_3.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_3.toml")),
}, },
wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"), wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"),
}, },
{ {
description: "test entropy value group", description: "test entropy value group",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_entropy_4.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_4.toml")),
}, },
wantErr: fmt.Errorf("strconv.ParseInt: parsing \"x\": invalid syntax"), wantErr: fmt.Errorf("strconv.ParseInt: parsing \"x\": invalid syntax"),
}, },
{ {
description: "test entropy value group", description: "test entropy value group",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_entropy_5.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_5.toml")),
}, },
wantErr: fmt.Errorf("problem loading config: group cannot be lower than 0"), wantErr: fmt.Errorf("problem loading config: group cannot be lower than 0"),
}, },
{ {
description: "test entropy value group", description: "test entropy value group",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_entropy_6.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_6.toml")),
}, },
wantErr: fmt.Errorf("problem loading config: group cannot be higher than number of groups in regexp"), wantErr: fmt.Errorf("problem loading config: group cannot be higher than number of groups in regexp"),
}, },
{ {
description: "test entropy range limits", description: "test entropy range limits",
opts: options.Options{ opts: options.Options{
ConfigPath: filepath.Join(configPath, "bad_entropy_7.toml"), ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_7.toml")),
}, },
wantErr: fmt.Errorf("problem loading config: invalid entropy ranges, must be within 0.0-8.0"), wantErr: fmt.Errorf("problem loading config: invalid entropy ranges, must be within 0.0-8.0"),
}, },
@@ -200,7 +200,7 @@ func findRuleByDescription(rules []config.Rule, description string) (*config.Rul
} }
func writeTestConfig(toml string) (string, error) { func writeTestConfig(toml string) (string, error) {
tmpfile, err := ioutil.TempFile("", "testConfig") tmpfile, err := ioutil.TempFile(".", "testConfig")
if err != nil { if err != nil {
return "", fmt.Errorf("Couldn't create test config got: %w", err) return "", fmt.Errorf("Couldn't create test config got: %w", err)
} }