I want to test a server. I want to start a server, perform some actions (e.g. add object, remove object, etc.) and shut it down.
package tests
import (
loads "github.com/go-openapi/loads"
"github.com/greenpau/app/internal/pkg/app/restapi"
"github.com/greenpau/app/internal/pkg/app/restapi/operations"
"testing"
)
func TestAppServer(t *testing.T) {
swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
if err != nil {
t.Fatalf("Failed loading swagger specification: %v", err)
}
api := operations.NewAppAPI(swaggerSpec)
server := restapi.NewServer(api)
defer server.Shutdown()
server.ConfigureAPI()
// TODO: create go routine to interact with the server (and shut it down) when it becomes available.
if err := server.Serve(); err != nil {
t.Fatalf("Server failed with: %v", err)
}
}
Now, running the test:
go test -v -run TestAppServer tests/*.go
=== RUN TestAppServer
2018/10/07 15:06:30 Serving app at unix://
2018/10/07 15:06:30 Serving app at http://[::]:34931
2018/10/07 15:06:30 the required flags `--tls-certificate` and `--tls-key` were not specified
FAIL command-line-arguments 0.073s
Is "the required flags --tls-certificate and --tls-key were not specified" really necessary? Perhaps having the flags default to something would be better?
N/A.
N/A.
N/A.
The swagger spec probably has https as scheme included.
When you run the server you want to specify the schemes, just like what we did for the unix socket in #1740
In this cases you can do
server := restapi.NewServer(api)
server.EnabledListeners = []string{"unix", "http"}
defer server.Shutdown()
The swagger spec probably has https as scheme included.
@casualjim , correct! Thank you!
At the end, I specified a single HTTP listener and port:
server := restapi.NewServer(api)
server.EnabledListeners = []string{"http"}
server.Port = 80
Most helpful comment
The swagger spec probably has https as scheme included.
When you run the server you want to specify the schemes, just like what we did for the unix socket in #1740
In this cases you can do