Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
How to run a Go server in Travis-CI?

I'm working on a Go project that exposes a RESTful http API.

I want to run the Go project and use Nodejs (Mocha) to test the endpoints. It seems as if the nohup command doesn't keep running in the background.

Locally everything works but I don't seem to be able to get it running in Travis-ci.

language: go
go:
  - 1.8
env:
  - "PATH=/home/travis/gopath/bin:$PATH"
before_install:
  - go get ./...
script:
  - npm install mocha -g
  - npm install
  - nohup go run ./cmd/server/main.go --scheme=http --port=8080 --host=127.0.0.1 &
  - mocha
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

First, you should seriously question whether writing tests in mocha makes sense. Admittedly, there might be cases when it does make sense (i.e. if you're porting a nodejs app to Go, and already have tests written for node). But even then, you should consider this a stop-gap measure, and write all new tests, and even migrate old tests, to Go as soon as possible.

But that aside, there's no reason you shouldn't be able to just start the process in the background normally. Perhaps with a shell script called from your Travis config (can often be cleaner and easier to follow than putting all commands in the config directly):

#!/bin/sh

go run &

mocha

If you really must run your tests in an external process, there are certain advantages from starting that from a Go test anyway. Namely, you can get test coverage stats, and starting can be more easily synchronized (so you don't need a sleep). To do this, you can follow my advice in this answer. Specifically, for the mocha case:

Write a test file that executes your main() function in a go routine:

func TestMainApp(t *testing.T) {
    go main() // Or whatever you need to do to start the server process
    cmd := exec.Command("mocha", ...)
    cmd.Start()
}

But seriously. You should write your tests in Go.

over 4 years ago · Santiago Trujillo Denunciar

0

Mocha runs directly after - nohup go run ./cmd/server/main.go --scheme=http --port=8080 --host=127.0.0.1 & so the server didn't start up yet.

Adding a sleep was enough.

script:
  - npm install mocha -g
  - npm install
  - nohup go run ./cmd/server/main.go --scheme=http --port=8080 --host=127.0.0.1 &
  - sleep 4
  - mocha

But, the point is taken, I will move to Go tests :-P

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda