diff options
author | Emiliano Ciavatta | 2020-04-01 15:03:19 +0000 |
---|---|---|
committer | Emiliano Ciavatta | 2020-04-01 15:03:19 +0000 |
commit | c2f10d25535ce9dd6e448434f1bd859e24d4f77b (patch) | |
tree | c32a592df17804ca7b747a36958c0ce3b8ed0ecc | |
parent | 2b9ccbe76c6975fe7cd09a3260ba459d59b9970a (diff) |
Add travis scripts
-rw-r--r-- | .travis.yml | 16 | ||||
-rw-r--r-- | Dockerfile | 1 | ||||
-rw-r--r-- | Dockerfile.env | 4 | ||||
-rw-r--r-- | docker-compose.testing.yml | 2 | ||||
-rw-r--r-- | storage_test.go | 14 | ||||
-rwxr-xr-x | travis_tests.sh | 18 |
6 files changed, 48 insertions, 7 deletions
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 @@ -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 |