github.com/cvmfs/docker-graphdriver@v0.0.0-20181206110523-155ec6df0521/repository-manager/test/test.bats (about) 1 2 # to run this tests you will need the utility bats. 3 # set the variable tool to the path of the actuall docker2cvmfs conversion 4 # utility 5 # the test automatically apply migration and remove database, be aware! 6 7 tool="../daemon --database $BATS_TMPDIR/db.sqlite" 8 9 function migrate_database { 10 sudo tool migrate-database --database "$BATS_TMPDIR/db.sqlite" 11 } 12 13 function print_output() { 14 lines=("$@") 15 for line in "${lines[@]}" 16 do 17 echo "# $line" >&3 18 done 19 } 20 21 function setup() { 22 run $tool migrate-database 23 run $tool add-user -u setup_user -r registry.hub.docker.com -p setup_pass 24 run $tool add-user -u setup_user -r registry.cern.ch -p setup_pass 25 } 26 27 function teardown() { 28 rm -f "$BATS_TMPDIR/db.sqlite" 29 } 30 31 @test "2 + 2 = 4" { 32 [ $((2 + 2)) -eq 4 ] 33 } 34 35 @test "invoke the daemon" { 36 run $tool 37 [ "$status" -eq 0 ] 38 } 39 40 @test "migration works" { 41 rm -f docker2cvmfs_archive.sqlite 42 43 run $tool migrate-database 44 [ "$status" -eq 0 ] 45 } 46 47 @test "add user" { 48 run $tool add-user -u simone -r cern -p pass 49 [ "$status" -eq 0 ] 50 51 run $tool list-users -z 52 [ "$status" -eq 0 ] 53 [ "${lines[0]}" = "user,registry" ] 54 [ "${lines[1]}" = "setup_user,registry.cern.ch" ] 55 [ "${lines[2]}" = "setup_user,registry.hub.docker.com" ] 56 [ "${lines[3]}" = "simone,cern" ] 57 } 58 59 @test "image syntax" { 60 run $tool check-image-syntax -z https://gitlab.cern.ch/foo/test/bar:v4@sha256:digest 61 62 [ "$status" -eq 0 ] 63 [ "${lines[0]}" = "name,user,scheme,registry,repository,tag,digest,is_thin" ] 64 [ "${lines[1]}" = "https://gitlab.cern.ch/foo/test/bar:v4@sha256:digest,,https,gitlab.cern.ch,foo/test/bar,v4,sha256:digest,false" ] 65 } 66 67 @test "add wish" { 68 run $tool add-wish \ 69 -i https://registry.hub.docker.com/atlas/athanalysis:latest \ 70 -o https://registry.cern.ch/atlas/thin/athanalysis:latest \ 71 -b setup_user \ 72 -r setup_registry 73 [ "$status" -eq 0 ] 74 75 run $tool list-wishes -z 76 [ "$status" -eq 0 ] 77 [ "${#lines[@]}" -eq 2 ] 78 [ "${lines[0]}" = "id,input_image_id,input_image_name,cvmfs_repo,output_image_id,output_image_name,converted" ] 79 [ "${lines[1]}" = "1,1,https://registry.hub.docker.com/atlas/athanalysis:latest,setup_registry,2,https://registry.cern.ch/atlas/thin/athanalysis:latest,false" ] 80 } 81 82 @test "add twice same wish result in error" { 83 run $tool add-wish \ 84 -i https://registry.hub.docker.com/atlas/athanalysis:latest \ 85 -o https://registry.cern.ch/atlas/thin/athanalysis:latest \ 86 -b setup_user \ 87 -r setup_registry 88 [ "$status" -eq 0 ] 89 run $tool add-wish \ 90 -i https://registry.hub.docker.com/atlas/athanalysis:latest \ 91 -o https://registry.cern.ch/atlas/thin/athanalysis:latest \ 92 -b setup_user \ 93 -r setup_registry 94 [ "$status" -ne 0 ] 95 } 96 97 @test "remove wish" { 98 run $tool add-wish \ 99 -i https://registry.hub.docker.com/atlas/athanalysis:latest \ 100 -o https://registry.cern.ch/atlas/thin/athanalysis:latest \ 101 -b setup_user \ 102 -r setup_registry 103 [ "$status" -eq 0 ] 104 105 run $tool remove-wish 1 106 [ "$status" -eq 0 ] 107 [ "${#lines[@]}" -eq 0 ] 108 109 run $tool list-wishes -z 110 [ "$status" -eq 0 ] 111 [ "${#lines[@]}" -eq 1 ] 112 }