Lint fix integration tests

This commit is contained in:
Kristoffer Dalby 2021-11-14 18:35:49 +01:00
parent 85f28a3f4a
commit ba084b9987
No known key found for this signature in database
GPG key ID: 09F62DC067465735
3 changed files with 13 additions and 6 deletions

View file

@ -88,6 +88,7 @@ func (s *IntegrationCLITestSuite) SetupTest() {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return fmt.Errorf("status code not OK") return fmt.Errorf("status code not OK")
} }
return nil return nil
}); err != nil { }); err != nil {
// TODO(kradalby): If we cannot access headscale, or any other fatal error during // TODO(kradalby): If we cannot access headscale, or any other fatal error during
@ -147,7 +148,6 @@ func (s *IntegrationCLITestSuite) TestNamespaceCommand() {
namespaces := make([]*v1.Namespace, len(names)) namespaces := make([]*v1.Namespace, len(names))
for index, namespaceName := range names { for index, namespaceName := range names {
namespace, err := s.createNamespace(namespaceName) namespace, err := s.createNamespace(namespaceName)
assert.Nil(s.T(), err) assert.Nil(s.T(), err)

View file

@ -12,6 +12,8 @@ import (
"github.com/ory/dockertest/v3/docker" "github.com/ory/dockertest/v3/docker"
) )
const DOCKER_EXECUTE_TIMEOUT = 10 * time.Second
func ExecuteCommand( func ExecuteCommand(
resource *dockertest.Resource, resource *dockertest.Resource,
cmd []string, cmd []string,
@ -21,7 +23,7 @@ func ExecuteCommand(
var stderr bytes.Buffer var stderr bytes.Buffer
// TODO(kradalby): Make configurable // TODO(kradalby): Make configurable
timeout := 10 * time.Second timeout := DOCKER_EXECUTE_TIMEOUT
type result struct { type result struct {
exitCode int exitCode int
@ -55,11 +57,13 @@ func ExecuteCommand(
fmt.Println("Command: ", cmd) fmt.Println("Command: ", cmd)
fmt.Println("stdout: ", stdout.String()) fmt.Println("stdout: ", stdout.String())
fmt.Println("stderr: ", stderr.String()) fmt.Println("stderr: ", stderr.String())
return "", fmt.Errorf("command failed with: %s", stderr.String()) return "", fmt.Errorf("command failed with: %s", stderr.String())
} }
return stdout.String(), nil return stdout.String(), nil
case <-time.After(timeout): case <-time.After(timeout):
return "", fmt.Errorf("command timed out after %s", timeout) return "", fmt.Errorf("command timed out after %s", timeout)
} }
} }

View file

@ -23,10 +23,9 @@ import (
"github.com/ory/dockertest/v3/docker" "github.com/ory/dockertest/v3/docker"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"inet.af/netaddr"
"tailscale.com/client/tailscale/apitype" "tailscale.com/client/tailscale/apitype"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"inet.af/netaddr"
) )
var tailscaleVersions = []string{"1.16.2", "1.14.3", "1.12.3"} var tailscaleVersions = []string{"1.16.2", "1.14.3", "1.12.3"}
@ -180,6 +179,7 @@ func (s *IntegrationTestSuite) tailscaleContainer(
log.Fatalf("Could not start resource: %s", err) log.Fatalf("Could not start resource: %s", err)
} }
fmt.Printf("Created %s container\n", hostname) fmt.Printf("Created %s container\n", hostname)
return hostname, pts return hostname, pts
} }
@ -248,13 +248,16 @@ func (s *IntegrationTestSuite) SetupSuite() {
if err := s.pool.Retry(func() error { if err := s.pool.Retry(func() error {
url := fmt.Sprintf("http://%s/health", hostEndpoint) url := fmt.Sprintf("http://%s/health", hostEndpoint)
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return err return err
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return fmt.Errorf("status code not OK") return fmt.Errorf("status code not OK")
} }
return nil return nil
}); err != nil { }); err != nil {
// TODO(kradalby): If we cannot access headscale, or any other fatal error during // TODO(kradalby): If we cannot access headscale, or any other fatal error during
@ -507,7 +510,6 @@ func (s *IntegrationTestSuite) TestSharedNodes() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
for _, machine := range machineList { for _, machine := range machineList {
result, err := ExecuteCommand( result, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
@ -607,7 +609,6 @@ func (s *IntegrationTestSuite) TestTailDrop() {
for peername, ip := range ips { for peername, ip := range ips {
s.T().Run(fmt.Sprintf("%s-%s", hostname, peername), func(t *testing.T) { s.T().Run(fmt.Sprintf("%s-%s", hostname, peername), func(t *testing.T) {
if peername != hostname { if peername != hostname {
// Under normal circumstances, we should be able to send a file // Under normal circumstances, we should be able to send a file
// using `tailscale file cp` - but not in userspace networking mode // using `tailscale file cp` - but not in userspace networking mode
// So curl! // So curl!
@ -770,6 +771,7 @@ func getIPs(tailscales map[string]dockertest.Resource) (map[string]netaddr.IP, e
ips[hostname] = ip ips[hostname] = ip
} }
return ips, nil return ips, nil
} }
@ -809,5 +811,6 @@ func getAPIURLs(
} }
} }
} }
return fts, nil return fts, nil
} }