-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathsettings_test.go
82 lines (72 loc) · 1.9 KB
/
settings_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package settings
import (
"fmt"
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-ls/internal/terraform/datadir"
)
func TestDecodeOptions_nil(t *testing.T) {
out, err := DecodeOptions(nil)
if err != nil {
t.Fatal(err)
}
opts := out.Options
if opts.IgnoreDirectoryNames != nil {
t.Fatalf("expected no options for nil, %#v given", opts.IgnoreDirectoryNames)
}
}
func TestDecodeOptions_wrongType(t *testing.T) {
_, err := DecodeOptions(map[string]interface{}{
"ignorePaths": "/random/path",
})
if err == nil {
t.Fatal("expected decoding of wrong type to result in error")
}
}
func TestDecodeOptions_success(t *testing.T) {
out, err := DecodeOptions(map[string]interface{}{
"ignorePaths": []string{"/random/path"},
})
if err != nil {
t.Fatal(err)
}
opts := out.Options
expectedPaths := []string{"/random/path"}
if diff := cmp.Diff(expectedPaths, opts.IgnorePaths); diff != "" {
t.Fatalf("options mismatch: %s", diff)
}
}
func TestValidate_IgnoreDirectoryNames_error(t *testing.T) {
tables := []struct {
input string
result string
}{
{datadir.DataDirName, `cannot ignore directory ".terraform"`},
{filepath.Join("path", "path"), fmt.Sprintf(`expected directory name, got a path: %q`, filepath.Join("path", "path"))},
}
for _, table := range tables {
out, err := DecodeOptions(map[string]interface{}{
"ignoreDirectoryNames": []string{table.input},
})
if err != nil {
t.Fatal(err)
}
result := out.Options.Validate()
if result.Error() != table.result {
t.Fatalf("expected error: %s, got: %s", table.result, result)
}
}
}
func TestValidate_IgnoreDirectoryNames_success(t *testing.T) {
out, err := DecodeOptions(map[string]interface{}{
"ignoreDirectoryNames": []string{"directory"},
})
if err != nil {
t.Fatal(err)
}
result := out.Options.Validate()
if result != nil {
t.Fatalf("did not expect error: %s", result)
}
}