-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSanityCheckTest.groovy
88 lines (69 loc) · 2.67 KB
/
SanityCheckTest.groovy
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
import groovy.json.JsonSlurper
import groovy.util.FileNameFinder
import static org.junit.Assert.*
import org.junit.*
class CustomIO {
def byteStream
def printStream
CustomIO() {
byteStream = new ByteArrayOutputStream()
printStream = new PrintStream(byteStream)
}
public String toString() {
return byteStream.toString("UTF-8")
}
}
class SanityCheckTest {
def execute(command) {
def proc = command.execute()
def outIO = new CustomIO()
def errIO = new CustomIO()
proc.waitForProcessOutput(outIO.printStream, errIO.printStream)
return [proc, outIO, errIO]
}
@Test
void sanityCheck() {
def (proc, out, err) = execute("/usr/src/app/pmd --codeFolder=/usr/src/app/fixtures/default --configFile=/usr/src/app/fixtures/default/config.json")
assert !out.toString().isEmpty()
assert proc.exitValue() == 0
}
@Test
void checkConfigBackwardCompatibility() {
def (proc, out, _err) = execute("/usr/src/app/pmd --codeFolder=/usr/src/app/fixtures/specified_file --configFile=/usr/src/app/fixtures/specified_file/config.new.json")
def (procOld, outOld, _errOld) = execute("/usr/src/app/pmd --codeFolder=/usr/src/app/fixtures/specified_file --configFile=/usr/src/app/fixtures/specified_file/config.old.json")
def expectedIssue = "Avoid modifying an outer loop incrementer in an inner loop for update expression"
assert proc.exitValue() == 0
assert proc.exitValue() == procOld.exitValue()
assert out.toString().contains(expectedIssue)
assert outOld.toString().contains(expectedIssue)
}
@Test
void abortOnBadConfig() {
def (proc, out, err) = execute("/usr/src/app/pmd --codeFolder=/usr/src/app/fixtures/bad_config --configFile=/usr/src/app/fixtures/bad_config/config.json")
assert !err.toString().isEmpty()
assert proc.exitValue() != 0
}
@Test
void engineCheckList() {
def engine = new JsonSlurper().parse(new File("engine.json"), "UTF-8")
assert engine.name
assert engine.description
assert engine.description.size() <= 140
assert engine.maintainer && engine.maintainer.name && engine.maintainer.email
assert engine.languages.size() > 0
assert engine.version
}
@Test
void dockerfileCheckList() {
def dockerfile = new File("Dockerfile").text
assert dockerfile.contains("MAINTAINER")
assert dockerfile.contains("VOLUME")
assert dockerfile.contains("WORKDIR")
assert dockerfile.contains("USER")
assert dockerfile.contains("CMD")
assert !dockerfile.toUpperCase().contains("EXPOSE")
assert !dockerfile.toUpperCase().contains("ONBUILD")
assert !dockerfile.toUpperCase().contains("ARG")
assert dockerfile.split("\n")[-1].startsWith("CMD")
}
}