github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/tests/integration/spec.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load helpers
     4  
     5  function setup() {
     6    # initial cleanup in case a prior test exited and did not cleanup
     7    cd "$INTEGRATION_ROOT"
     8    run rm -f -r "$HELLO_BUNDLE"
     9  
    10    # setup hello-world for spec generation testing
    11    run mkdir "$HELLO_BUNDLE"
    12    run mkdir "$HELLO_BUNDLE"/rootfs
    13    run tar -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
    14  }
    15  
    16  function teardown() {
    17    cd "$INTEGRATION_ROOT"
    18    run rm -f -r "$HELLO_BUNDLE"
    19  }
    20  
    21  @test "spec generation cwd" {
    22    cd "$HELLO_BUNDLE"
    23    # note this test runs from the bundle not the integration root
    24  
    25    # test that config.json does not exist after the above partial setup
    26    [ ! -e config.json ]
    27  
    28    # test generation of spec does not return an error
    29    runc spec
    30    [ "$status" -eq 0 ]
    31  
    32    # test generation of spec created our config.json (spec)
    33    [ -e config.json ]
    34  
    35    # test existence of required args parameter in the generated config.json
    36    run bash -c "grep -A2 'args' config.json | grep 'sh'"
    37    [[ "${output}" == *"sh"* ]]
    38  
    39    # change the default args parameter from sh to hello
    40    sed -i 's;"sh";"/hello";' config.json
    41  
    42    # ensure the generated spec works by running hello-world
    43    runc run test_hello
    44    [ "$status" -eq 0 ]
    45  }
    46  
    47  @test "spec generation --bundle" {
    48    # note this test runs from the integration root not the bundle
    49  
    50    # test that config.json does not exist after the above partial setup
    51    [ ! -e "$HELLO_BUNDLE"/config.json ]
    52  
    53    # test generation of spec does not return an error
    54    runc spec --bundle "$HELLO_BUNDLE"
    55    [ "$status" -eq 0 ]
    56  
    57    # test generation of spec created our config.json (spec)
    58    [ -e "$HELLO_BUNDLE"/config.json ]
    59  
    60    # change the default args parameter from sh to hello
    61    sed -i 's;"sh";"/hello";' "$HELLO_BUNDLE"/config.json
    62  
    63    # ensure the generated spec works by running hello-world
    64    runc run --bundle "$HELLO_BUNDLE" test_hello
    65    [ "$status" -eq 0 ]
    66  }
    67  
    68  @test "spec validator" {
    69    TESTDIR=$(pwd)
    70    cd "$HELLO_BUNDLE"
    71  
    72    run git clone https://github.com/opencontainers/runtime-spec.git src/runtime-spec
    73    [ "$status" -eq 0 ]
    74  
    75    SPEC_COMMIT=$(grep runtime-spec ${TESTDIR}/../../Godeps/Godeps.json -A 4 | grep Rev | cut -d":" -f 2 | tr -d ' "')
    76    (
    77      cd src/runtime-spec &&
    78      run git reset --hard "${SPEC_COMMIT}"
    79    )
    80    [ "$status" -eq 0 ]
    81    [ -e src/runtime-spec/schema/config-schema.json ]
    82  
    83    run bash -c "GOPATH='$GOPATH' go get github.com/xeipuuv/gojsonschema"
    84    [ "$status" -eq 0 ]
    85  
    86    GOPATH="$GOPATH" go build src/runtime-spec/schema/validate.go
    87    [ -e ./validate ]
    88  
    89    runc spec
    90    [ -e config.json ]
    91  
    92    run ./validate src/runtime-spec/schema/config-schema.json config.json
    93    [ "$status" -eq 0 ]
    94    [[ "${lines[0]}" == *"The document is valid"* ]]
    95  }