Since go 1.7, "context" is a standard package. Since go 1.9,
x/net/context merely provides some types aliased to those in
the standard context package.
The changes were performed by the following script:
for f in $(git ls-files \*.go | grep -v ^vendor/); do
sed -i 's|golang.org/x/net/context|context|' $f
goimports -w $f
for i in 1 2; do
awk '/^$/ {e=1; next;}
/\t"context"$/ {e=0;}
{if (e) {print ""; e=0}; print;}' < $f > $f.new && \
mv $f.new $f
goimports -w $f
done
done
[v2: do awk/goimports fixup twice]
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package swarm
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/docker/cli/internal/test/network"
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type notFound struct {
|
|
error
|
|
}
|
|
|
|
func (n notFound) NotFound() bool {
|
|
return true
|
|
}
|
|
|
|
func TestValidateExternalNetworks(t *testing.T) {
|
|
var testcases = []struct {
|
|
inspectResponse types.NetworkResource
|
|
inspectError error
|
|
expectedMsg string
|
|
network string
|
|
}{
|
|
{
|
|
inspectError: notFound{},
|
|
expectedMsg: "could not be found. You need to create a swarm-scoped network",
|
|
},
|
|
{
|
|
inspectError: errors.New("Unexpected"),
|
|
expectedMsg: "Unexpected",
|
|
},
|
|
// FIXME(vdemeester) that doesn't work under windows, the check needs to be smarter
|
|
/*
|
|
{
|
|
inspectError: errors.New("host net does not exist on swarm classic"),
|
|
network: "host",
|
|
},
|
|
*/
|
|
{
|
|
network: "user",
|
|
expectedMsg: "is not in the right scope",
|
|
},
|
|
{
|
|
network: "user",
|
|
inspectResponse: types.NetworkResource{Scope: "swarm"},
|
|
},
|
|
}
|
|
|
|
for _, testcase := range testcases {
|
|
fakeClient := &network.FakeClient{
|
|
NetworkInspectFunc: func(_ context.Context, _ string, _ types.NetworkInspectOptions) (types.NetworkResource, error) {
|
|
return testcase.inspectResponse, testcase.inspectError
|
|
},
|
|
}
|
|
networks := []string{testcase.network}
|
|
err := validateExternalNetworks(context.Background(), fakeClient, networks)
|
|
if testcase.expectedMsg == "" {
|
|
assert.NilError(t, err)
|
|
} else {
|
|
assert.ErrorContains(t, err, testcase.expectedMsg)
|
|
}
|
|
}
|
|
}
|