Go-swagger: testing server: the required flags `--tls-certificate` and `--tls-key` were not specified

Created on 7 Oct 2018  路  3Comments  路  Source: go-swagger/go-swagger

Problem statement

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?

Swagger specification

N/A.

Steps to reproduce

N/A.

Environment

N/A.

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

server := restapi.NewServer(api)
server.EnabledListeners = []string{"unix", "http"}
defer server.Shutdown()

All 3 comments

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
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ribice picture ribice  路  4Comments

piotrkowalczuk picture piotrkowalczuk  路  4Comments

mpalomas picture mpalomas  路  5Comments

flier picture flier  路  5Comments

Ragnar-BY picture Ragnar-BY  路  3Comments