summaryrefslogtreecommitdiff
path: root/test/handler/test_terraform_handler.vader
blob: 4be89cb12ce50f132162f274c156b35295e3d70a (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
Before:
  " Load the file which defines the linter.
  runtime ale_linters/terraform/terraform.vim
  call ale#test#SetDirectory('/testplugin/test/test-files/terraform')
  call ale#test#SetFilename('providers.tf')

After:
  " Unload all linters again.
  call ale#linter#Reset()
  call ale#test#RestoreDirectory()

Execute(The output should be correct):
  AssertEqual
  \ [
  \   {
  \     'lnum': 17,
  \     'col': 13,
  \     'filename': ale#path#Simplify(g:dir . '/providers.tf'),
  \     'type': 'W',
  \     'text': 'Terraform 0.13 and earlier allowed provider version',
  \   },
  \   {
  \     'lnum': 0,
  \     'col': 0,
  \     'filename': ale#path#Simplify(g:dir . '/providers.tf'),
  \     'type': 'E',
  \     'text': 'Plugin reinitialization required. Please run "terraform"',
  \   }
  \ ],
  \ ale_linters#terraform#terraform#Handle(bufnr(''), [
  \ '{',
  \ '"valid": false,',
  \ '"error_count": 1,',
  \ '"warning_count": 1,',
  \ '"diagnostics": [',
  \ '  {',
  \ '    "severity": "warning",',
  \ '    "summary": "Version constraints inside provider configuration blocks are deprecated",',
  \ '    "detail": "Terraform 0.13 and earlier allowed provider version",',
  \ '    "range": {',
  \ '      "filename": "providers.tf",',
  \ '      "start": {',
  \ '        "line": 17,',
  \ '        "column": 13,',
  \ '        "byte": 669',
  \ '      },',
  \ '      "end": {',
  \ '        "line": 17,',
  \ '        "column": 24,',
  \ '        "byte": 680',
  \ '      }',
  \ '    }',
  \ '  },',
  \ '  {',
  \ '    "severity": "error",',
  \ '    "summary": "Could not load plugin",',
  \ '    "detail": "Plugin reinitialization required. Please run \"terraform\""',
  \ '  }',
  \ '  ]',
  \ '}',
  \ ])

Execute(Should use summary if detail not available):
  AssertEqual
  \ [
  \   {
  \     'lnum': 91,
  \     'col': 41,
  \     'filename': ale#path#Simplify(g:dir . '/main.tf'),
  \     'type': 'E',
  \     'text': 'storage_os_disk: required field is not set',
  \   }
  \ ],
  \ ale_linters#terraform#terraform#Handle(bufnr(''), [
  \ '{',
  \ '  "valid": false,',
  \ '  "error_count": 1,',
  \ '  "warning_count": 0,',
  \ '  "diagnostics": [',
  \ '    {',
  \ '      "severity": "error",',
  \ '      "summary": "storage_os_disk: required field is not set",',
  \ '      "range": {',
  \ '        "filename": "main.tf",',
  \ '        "start": {',
  \ '          "line": 91,',
  \ '          "column": 41,',
  \ '          "byte": 2381',
  \ '        },',
  \ '        "end": {',
  \ '          "line": 91,',
  \ '          "column": 41,',
  \ '          "byte": 2381',
  \ '        }',
  \ '      }',
  \ '    }',
  \ '  ]',
  \ '}'
  \ ])

Execute(Should use summary if detail available but empty):
  AssertEqual
  \ [
  \   {
  \     'lnum': 91,
  \     'col': 41,
  \     'filename': ale#path#Simplify(g:dir . '/main.tf'),
  \     'type': 'E',
  \     'text': 'storage_os_disk: required field is not set',
  \   }
  \ ],
  \ ale_linters#terraform#terraform#Handle(bufnr(''), [
  \ '{',
  \ '  "valid": false,',
  \ '  "error_count": 1,',
  \ '  "warning_count": 0,',
  \ '  "diagnostics": [',
  \ '    {',
  \ '      "severity": "error",',
  \ '      "summary": "storage_os_disk: required field is not set",',
  \ '      "detail": "",',
  \ '      "range": {',
  \ '        "filename": "main.tf",',
  \ '        "start": {',
  \ '          "line": 91,',
  \ '          "column": 41,',
  \ '          "byte": 2381',
  \ '        },',
  \ '        "end": {',
  \ '          "line": 91,',
  \ '          "column": 41,',
  \ '          "byte": 2381',
  \ '        }',
  \ '      }',
  \ '    }',
  \ '  ]',
  \ '}'
  \ ])