-1

I'm new to this tool and looking for help with what I'm sure is a common issue.

As I understand dredd isn't able to kill processes that it started, for me this is main.go.

My test feature is working great but the second time I obviously run into issues at the port is in use.

I've read most of the articles and guides out there but I'm not able to understand how to implement the necessary fix.

I tried creating script/test.sh

  #!/bin/sh
  go run main.go
  sleep 3
  PID=$!
  dredd apiary.apib http://localhost:5000/
  RESULT=$?
  kill -9 $PID
  exit $RESULT

and then running ./scripts/test.sh instead of dredd but its not working at all.

What is the best way to implement a fix for this that would also work on circleCI?

Kaigo
  • 1,267
  • 2
  • 14
  • 33
  • have you tried adding `defer server.Listener.Close()` to the end of the `main` func? – Derek Pollard May 30 '18 at 20:48
  • `main.go` is a source file, not a process or even an executable. how are you running your process? – JimB May 30 '18 at 20:48
  • I'm just running `go run main.go` thanks – Kaigo May 30 '18 at 20:49
  • With adding the `defer server.Listener.Close()` i get syntax error `srv.Listener undefined (type *http.Server has no field or method Listener)` – Kaigo May 30 '18 at 20:52
  • Try compiling the binary and running it directly (not sure what the defer would solve, since the process is being interrupted, plus defers don't even run after exiting via a signal). – JimB May 30 '18 at 20:55
  • will that work as i need to run the web server? – Kaigo May 30 '18 at 21:28
  • 1
    no your right, "Using Dredd with Go is slightly different to other languages, as a binary needs to be compiled for execution" https://dredd.readthedocs.io/en/latest/hooks-go.html – Kaigo May 30 '18 at 21:30
  • still not sure how to implement though. . – Kaigo May 30 '18 at 21:32

1 Answers1

0

figured it out.

I had to delete the dredd.yml file and run

$ go build

then

$ dredd apiary.apib http://127.0.0.1:5000 --server=./go-project --language=go

But circleCI testing is not working, it just seems to ignore the circle.yml file and skips straight past it.

Kaigo
  • 1,267
  • 2
  • 14
  • 33