Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda