vendredi 1 avril 2016

Web API (Golang) test in Drone.io

I need to test my RESTApi inside drone.io build with Golang and Posgresql . So for this i have to run the server first then mock the endpoint . I have tried many way but could not seem to run the service and then run the test .. Just want to run the server as a service container in background and then run test on this .

This is my .drone.yml file

clone:
  path: http://ift.tt/1VZ0KmJ
compose:
  database:
    image: postgres
    environment:
      - POSTGRES_PASSWORD=pass
      - POSTGRES_USER=user
      - POSTGRES_DB=auth
  redis:
    image: tutum/redis
    environment:
      - REDIS_PASS=pass
  api:
    image: golang
    environment:
      - EXPOSE_PORT=:6201
      - DB_1_PORT_5432_TCP_ADDR=localhost
      - POSTGRES_PASSWORD=pass
      - POSTGRES_USER=user
      - POSTGRES_DB=auth
      - REDIS_PORT_6379_TCP_ADDR=localhost
      - REDIS_PORT_6379_TCP_PORT=6379
      - REDIS_PASS=pass
    commands:
      - go get ./...
      - go run server.go run
    privileged: true

build:
  image: golang
  environment:
    - EXPOSE_PORT=:6201
    - DB_1_PORT_5432_TCP_ADDR=localhost
    - POSTGRES_PASSWORD=pass
    - POSTGRES_USER=user
    - POSTGRES_DB=auth
    - REDIS_PORT_6379_TCP_ADDR=localhost
    - REDIS_PORT_6379_TCP_PORT=6379
    - REDIS_PASS=pass
  commands:
    - go get ./...
    - go test -v

I tried to run API as a service container because my tests needs them like database . So far service containers database and redis works well but i think my api is not running as service container in the background .

Api test failed because it could not find the api route .

Aucun commentaire:

Enregistrer un commentaire