summaryrefslogtreecommitdiff
path: root/test/test_dockerfile_hadolint_linter.vader
blob: ba7e2187ae50dead32185ee4c3d555ca7d73566b (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
" NOTE: We use the 'b:' forms below to ensure that we're properly using
" ale#Var()

Given dockerfile:
  #

Before:
  Save g:ale_dockerfile_hadolint_use_docker
  Save g:ale_dockerfile_hadolint_docker_image
  silent! unlet g:ale_dockerfile_hadolint_use_docker
  silent! unlet g:ale_dockerfile_hadolint_docker_image

  " enable loading inside test container
  silent! cd /testplugin
  source ale_linters/dockerfile/hadolint.vim


After:
  Restore
  silent! unlet b:ale_dockerfile_hadolint_use_docker
  silent! unlet b:ale_dockerfile_hadolint_docker_image
  silent! unlet b:ale_dockerfile_hadolint_options


Execute(linter honors ..._use_docker correctly):

  " default: never
  AssertEqual
  \ 'hadolint',
  \ ale_linters#dockerfile#hadolint#GetExecutable(bufnr(''))

  " explicit never
  let b:ale_dockerfile_hadolint_use_docker = 'never'
  AssertEqual
  \ 'hadolint',
  \ ale_linters#dockerfile#hadolint#GetExecutable(bufnr(''))

  let b:ale_dockerfile_hadolint_use_docker = 'always'
  AssertEqual
  \ 'docker',
  \ ale_linters#dockerfile#hadolint#GetExecutable(bufnr(''))

  " hadolint if present, otherwise docker
  let command = 'docker'
  if executable('hadolint')
    let command = 'hadolint'
  endif

  let b:ale_dockerfile_hadolint_use_docker = 'yes'
  AssertEqual
  \ command,
  \ ale_linters#dockerfile#hadolint#GetExecutable(bufnr(''))


Execute(command is correct when using docker):
  let b:ale_dockerfile_hadolint_use_docker = 'always'

  AssertEqual
  \ "docker run --rm -i hadolint/hadolint hadolint  --no-color -",
  \ ale_linters#dockerfile#hadolint#GetCommand(bufnr(''))

Execute(command is correct when using docker and supplying options):
  let b:ale_dockerfile_hadolint_use_docker = 'always'
  let b:ale_dockerfile_hadolint_options = '--ignore DL3006'

  AssertEqual
  \ "docker run --rm -i hadolint/hadolint hadolint --ignore DL3006 --no-color -",
  \ ale_linters#dockerfile#hadolint#GetCommand(bufnr(''))

Execute(command is correct when not docker):
  let b:ale_dockerfile_hadolint_use_docker = 'never'

  AssertEqual
  \ "hadolint  --no-color -",
  \ ale_linters#dockerfile#hadolint#GetCommand(bufnr(''))

Execute(command is correct when not docker and supplying options):
  let b:ale_dockerfile_hadolint_use_docker = 'never'
  let b:ale_dockerfile_hadolint_options = '--ignore DL3006'

  AssertEqual
  \ "hadolint --ignore DL3006 --no-color -",
  \ ale_linters#dockerfile#hadolint#GetCommand(bufnr(''))

Execute(test warnings from hadolint):
  AssertEqual
  \ [{'lnum': 10, 'col': 0, 'type': 'W', 'code': 'DL3007', 'text': 'DL3007: Using latest is prone to errors', 'detail': "DL3007 ( https://github.com/hadolint/hadolint/wiki/DL3007 )\n\nUsing latest is prone to errors"}],
  \ ale_linters#dockerfile#hadolint#Handle(bufnr(''), [
  \ '-:10 DL3007 warning: Using latest is prone to errors',
  \ ])

Execute(test warnings from shellcheck):
  AssertEqual
  \ [{'lnum': 3, 'col': 0, 'type': 'W', 'code': 'SC2154', 'text': 'SC2154: bar is referenced but not assigned.', 'detail': "SC2154 ( https://github.com/koalaman/shellcheck/wiki/SC2154 )\n\nbar is referenced but not assigned."}],
  \ ale_linters#dockerfile#hadolint#Handle(bufnr(''), [
  \ '-:3 SC2154 warning: bar is referenced but not assigned.',
  \ ])

Execute(test errors from dockerfile parser):
  AssertEqual
  \ [{'lnum': 3, 'col': 4, 'type': 'E', 'text': 'unexpected "A" expecting at least one space after ''RUN''', 'detail': 'hadolint could not parse the file because of a syntax error.'}],
  \ ale_linters#dockerfile#hadolint#Handle(bufnr(''), [
  \ "/dev/stdin:3:4 unexpected \"A\" expecting at least one space after 'RUN'",
  \ ])

" fin...