File: spec.bats

package info (click to toggle)
runc 1.0.0~rc6%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,972 kB
  • sloc: sh: 1,386; ansic: 946; makefile: 117
file content (96 lines) | stat: -rw-r--r-- 2,749 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env bats

load helpers

function setup() {
  # initial cleanup in case a prior test exited and did not cleanup
  cd "$INTEGRATION_ROOT"
  run rm -f -r "$HELLO_BUNDLE"

  # setup hello-world for spec generation testing
  run mkdir "$HELLO_BUNDLE"
  run mkdir "$HELLO_BUNDLE"/rootfs
  run tar -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
}

function teardown() {
  cd "$INTEGRATION_ROOT"
  run rm -f -r "$HELLO_BUNDLE"
}

@test "spec generation cwd" {
  cd "$HELLO_BUNDLE"
  # note this test runs from the bundle not the integration root

  # test that config.json does not exist after the above partial setup
  [ ! -e config.json ]

  # test generation of spec does not return an error
  runc_spec
  [ "$status" -eq 0 ]

  # test generation of spec created our config.json (spec)
  [ -e config.json ]

  # test existence of required args parameter in the generated config.json
  run bash -c "grep -A2 'args' config.json | grep 'sh'"
  [[ "${output}" == *"sh"* ]]

  # change the default args parameter from sh to hello
  sed -i 's;"sh";"/hello";' config.json

  # ensure the generated spec works by running hello-world
  runc run test_hello
  [ "$status" -eq 0 ]
}

@test "spec generation --bundle" {
  # note this test runs from the integration root not the bundle

  # test that config.json does not exist after the above partial setup
  [ ! -e "$HELLO_BUNDLE"/config.json ]

  # test generation of spec does not return an error
  runc_spec "$HELLO_BUNDLE"
  [ "$status" -eq 0 ]

  # test generation of spec created our config.json (spec)
  [ -e "$HELLO_BUNDLE"/config.json ]

  # change the default args parameter from sh to hello
  sed -i 's;"sh";"/hello";' "$HELLO_BUNDLE"/config.json

  # ensure the generated spec works by running hello-world
  runc run --bundle "$HELLO_BUNDLE" test_hello
  [ "$status" -eq 0 ]
}

@test "spec validator" {
  TESTDIR=$(pwd)
  cd "$HELLO_BUNDLE"

  run git clone https://github.com/opencontainers/runtime-spec.git src/runtime-spec
  [ "$status" -eq 0 ]

  SPEC_COMMIT=$(grep '^github.com/opencontainers/runtime-spec' ${TESTDIR}/../../vendor.conf | cut -d ' ' -f 2)
  run git -C src/runtime-spec reset --hard "${SPEC_COMMIT}"

  [ "$status" -eq 0 ]
  [ -e src/runtime-spec/schema/config-schema.json ]

  run bash -c "GOPATH='$GOPATH' go get github.com/xeipuuv/gojsonschema"
  [ "$status" -eq 0 ]

  run git -C "${GOPATH}/src/github.com/xeipuuv/gojsonschema" reset --hard 6637feb73ee44cd4640bb3def285c29774234c7f
  [ "$status" -eq 0 ]

  GOPATH="$GOPATH" go build src/runtime-spec/schema/validate.go
  [ -e ./validate ]

  runc spec
  [ -e config.json ]

  run ./validate src/runtime-spec/schema/config-schema.json config.json
  [ "$status" -eq 0 ]
  [[ "${lines[0]}" == *"The document is valid"* ]]
}