From c2f10d25535ce9dd6e448434f1bd859e24d4f77b Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Wed, 1 Apr 2020 17:03:19 +0200 Subject: Add travis scripts --- .travis.yml | 16 ++++++++++++++++ Dockerfile | 1 - Dockerfile.env | 4 ++-- docker-compose.testing.yml | 2 +- storage_test.go | 14 +++++++++++--- travis_tests.sh | 18 ++++++++++++++++++ 6 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 .travis.yml create mode 100755 travis_tests.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..801a37f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: bash + +sudo: required +services: + - docker + +before_script: + - docker pull eciavatta/caronte-env + - docker-compose -f docker-compose.testing.yml up -d --build + +script: + - docker logs -f caronte_caronte_1 | grep "travis" | (read status; if $status -eq "travis_tests_fails"; then exit 1; fi) + +after_script: + - docker logs caronte_caronte_1 + - docker-compose down diff --git a/Dockerfile b/Dockerfile index 2a1ffc8..0c6f4f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,3 @@ WORKDIR /caronte RUN go mod download && go build CMD ./caronte - diff --git a/Dockerfile.env b/Dockerfile.env index 844be8e..5c00d32 100644 --- a/Dockerfile.env +++ b/Dockerfile.env @@ -29,7 +29,8 @@ RUN wget https://github.com/intel/hyperscan/archive/v$HYPERSCAN_VERSION.tar.gz - cmake -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DBUILD_STATIC_AND_SHARED=1 \ -DBOOST_ROOT=/tmp/boost_1_72_0 .. && \ make && \ - make install + make install && \ + ln -s /usr/local/lib/libhs.so.5 /usr/lib/libhs.so.5 # Get GoLang and install it RUN wget https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz -P /tmp && \ @@ -39,4 +40,3 @@ RUN wget https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz -P /tmp && \ RUN rm -rf /tmp/* CMD /bin/bash - diff --git a/docker-compose.testing.yml b/docker-compose.testing.yml index c4eff8e..019628c 100644 --- a/docker-compose.testing.yml +++ b/docker-compose.testing.yml @@ -18,7 +18,7 @@ services: - mongo networks: - caronte-net - command: "./caronte" + command: "./travis_tests.sh" environment: MONGO_HOST: mongo MONGO_PORT: 27017 diff --git a/storage_test.go b/storage_test.go index 5356596..32a10a6 100644 --- a/storage_test.go +++ b/storage_test.go @@ -94,16 +94,24 @@ func testFindOne(t *testing.T) { } } - - func TestBasicOperations(t *testing.T) { t.Run("testInsert", testInsert) t.Run("testFindOne", testFindOne) } func TestMain(m *testing.M) { + mongoHost, ok := os.LookupEnv("MONGO_HOST") + if !ok { + mongoHost = "localhost" + } + mongoPort, ok := os.LookupEnv("MONGO_PORT") + if !ok { + mongoHost = "27017" + } + uniqueDatabaseName := sha256.Sum256([]byte(time.Now().String())) - client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017")) + + client, err := mongo.NewClient(options.Client().ApplyURI(fmt.Sprintf("mongodb://%s:%v", mongoHost, mongoPort))) if err != nil { panic("failed to create mongo client") } diff --git a/travis_tests.sh b/travis_tests.sh new file mode 100755 index 0000000..cb4363c --- /dev/null +++ b/travis_tests.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# wait mongodb server +sleep 10 + +# run tests +go test -v + +RET_CODE=$? + +# +if [ $RET_CODE -eq 0 ]; then + echo "travis_tests_success" +else + echo "travis_tests_fails" +fi + +exit $RET_CODE -- cgit v1.2.3-70-g09d2