diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 601a2bdaf10f5ffbb3561450eeebe691a2187959..5f3e55df54dd162368189e4c18475f1d2f18a95b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,27 +7,32 @@ compile: artifacts: paths: - bin/ + - build/ tags: - - build + - regular - debian script: - echo "Estágio 'build'" - - apt-get update && apt-get install -y build-essential && apt-get install -y cmake - - apt-get install -y git + - apt-get update && apt-get install -y build-essential cmake git - git submodule init - git submodule update --init --recursive - mkdir build - cd build - - cmake .. + - cmake -DPRINT_JSON=ON .. - make testDebian: stage: test tags: - - build + - regular - debian script: - - echo "It works debian:8" + - apt-get update && apt-get install -y git jq + - git clone https://github.com/sstephenson/bats.git + - cd bats + - ./install.sh /usr + - cd ../test + - ./returnTest.bats dependencies: - compile @@ -35,7 +40,22 @@ testUbuntu: stage: test tags: - ubuntu + - regular script: - - echo "It works Ubuntu:16.04" + - apt-get update && apt-get install -y bats jq + - cd test + - ./returnTest.bats + dependencies: + - compile + +testOpensuse: + stage: test + tags: + - opensuse + script: + - zypper -n update + - zypper -n install bats && zypper -n install jq + - cd test + - ./returnTest.bats dependencies: - compile diff --git a/test/returnTest.bats b/test/returnTest.bats new file mode 100755 index 0000000000000000000000000000000000000000..1339dc2f7ac45e2907844cce25f7686ceca8589d --- /dev/null +++ b/test/returnTest.bats @@ -0,0 +1,93 @@ +#!/usr/bin/env bats + +function amount_users() { + obj=$(cat export.json | jq -r '.data.amount_users') + [[ "$obj" -eq "$obj" ]] && [[ "$obj" != "null" ]] +} + +function mac_address() { + obj=$(cat export.json | jq -r '.data.mac_address') + [[ "$obj" =~ ^(..:){5}..$ ]] && [[ "$obj" != "null" ]] +} + +function machine_type() { + obj=$(cat export.json | jq -r '.data.machine_type') + [[ "$obj" != "null" ]] +} + +function memory() { + obj=$(cat export.json | jq -r '.data.memory') + [[ "$obj" -eq "$obj" ]] && [[ "$obj" != "null" ]] +} + +function os_distro() { + obj=$(cat export.json | jq -r '.data.os_distro') + [[ "$obj" != "null" ]] +} + +function os_kernel() { + obj=$(cat export.json | jq -r '.data.os_kernel') + [[ "$obj" != "null" ]] +} + +function os_type() { + obj=$(cat export.json | jq -r '.data.os_type') + [[ "$obj" != "null" ]] +} + +function processor() { + obj=$(cat export.json | jq -r '.data.processor') + [[ "$obj" != "null" ]] +} + +setup() { + ./../bin/agent-v0.0 | head -n -2 > export.json + [ -s export.json ] + cat export.json +} + +teardown() { + rm -f export.json +} + +@test "Amount Users" { + run amount_users + [ "$status" -eq 0 ] +} + +@test "MAC" { + run mac_address + [ "$status" -eq 0 ] +} + +@test "Machine Type" { + run machine_type + [ "$status" -eq 0 ] +} + +@test "Memory" { + skip + run memory + [ "$status" -eq 0 ] +} + +@test "OS Distro" { + run os_distro + [ "$status" -eq 0 ] +} + +@test "OS Kernel" { + run os_kernel + [ "$status" -eq 0 ] +} + +@test "OS Type" { + run os_type + [ "$status" -eq 0 ] +} + +@test "Processor" { + skip + run processor + [ "$status" -eq 0 ] +}