From b11a336a339fbbca08902d7e6b3fba57cf1867f1 Mon Sep 17 00:00:00 2001 From: Caleb Doxsey Date: Tue, 28 Apr 2020 08:17:22 -0600 Subject: [PATCH] inegration: fix linting issues --- integration/internal/cluster/certs.go | 1 + integration/internal/cluster/cluster.go | 5 +++++ integration/internal/cluster/config.go | 6 ------ integration/internal/cluster/setup.go | 4 ++-- integration/internal/flows/flows.go | 1 + integration/internal/forms/forms.go | 2 ++ integration/internal/httputil/httputil.go | 3 +++ integration/main_test.go | 11 +++++++---- 8 files changed, 21 insertions(+), 12 deletions(-) delete mode 100644 integration/internal/cluster/config.go diff --git a/integration/internal/cluster/certs.go b/integration/internal/cluster/certs.go index be41ab1bf..f3c0f5884 100644 --- a/integration/internal/cluster/certs.go +++ b/integration/internal/cluster/certs.go @@ -12,6 +12,7 @@ import ( "github.com/google/uuid" ) +// TLSCerts holds the certificate authority, certificate and certificate key for a TLS connection. type TLSCerts struct { CA string Cert string diff --git a/integration/internal/cluster/cluster.go b/integration/internal/cluster/cluster.go index dfca3c3cd..7e07b3ed2 100644 --- a/integration/internal/cluster/cluster.go +++ b/integration/internal/cluster/cluster.go @@ -1,3 +1,4 @@ +// Package cluster is used to configure a kubernetes cluster for testing. package cluster import ( @@ -8,6 +9,7 @@ import ( "golang.org/x/net/publicsuffix" ) +// A Cluster is used to configure a kubernetes cluster. type Cluster struct { workingDir string @@ -15,12 +17,15 @@ type Cluster struct { certs *TLSCerts } +// New creates a new Cluster. func New(workingDir string) *Cluster { return &Cluster{ workingDir: workingDir, } } +// NewHTTPClient creates a new *http.Client, with a cookie jar, and a LocalRoundTripper +// which routes traffic to the nginx ingress controller. func (cluster *Cluster) NewHTTPClient() *http.Client { jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) if err != nil { diff --git a/integration/internal/cluster/config.go b/integration/internal/cluster/config.go deleted file mode 100644 index 3e07385f2..000000000 --- a/integration/internal/cluster/config.go +++ /dev/null @@ -1,6 +0,0 @@ -package cluster - -type Config struct { - WorkingDirectory string - HTTPSPort int -} diff --git a/integration/internal/cluster/setup.go b/integration/internal/cluster/setup.go index cd37f3d5d..a96323ff9 100644 --- a/integration/internal/cluster/setup.go +++ b/integration/internal/cluster/setup.go @@ -40,7 +40,7 @@ func (cluster *Cluster) Setup(ctx context.Context) error { return err } - jsonsrc, err := cluster.generateManifests(ctx) + jsonsrc, err := cluster.generateManifests() if err != nil { return err } @@ -136,7 +136,7 @@ func (cluster *Cluster) getNodeHTTPSAddr(ctx context.Context) (hostport string, return net.JoinHostPort(hostIP, port), nil } -func (cluster *Cluster) generateManifests(ctx context.Context) (string, error) { +func (cluster *Cluster) generateManifests() (string, error) { src, err := ioutil.ReadFile(filepath.Join(cluster.workingDir, "manifests", "manifests.jsonnet")) if err != nil { return "", fmt.Errorf("error reading manifest jsonnet src: %w", err) diff --git a/integration/internal/flows/flows.go b/integration/internal/flows/flows.go index aea0f56cc..9c9d6469b 100644 --- a/integration/internal/flows/flows.go +++ b/integration/internal/flows/flows.go @@ -1,3 +1,4 @@ +// Package flows has helper functions for working with pomerium end-user use-case flows. package flows import ( diff --git a/integration/internal/forms/forms.go b/integration/internal/forms/forms.go index df255b685..e0ccf2d6c 100644 --- a/integration/internal/forms/forms.go +++ b/integration/internal/forms/forms.go @@ -1,3 +1,4 @@ +// Package forms has helper functions for working with HTML forms. package forms import ( @@ -69,6 +70,7 @@ func Parse(r io.Reader) []Form { return forms } +// NewRequestWithContext creates a new request from the form details. func (f *Form) NewRequestWithContext(ctx context.Context, baseURL *url.URL) (*http.Request, error) { actionURL, err := url.Parse(f.Action) if err != nil { diff --git a/integration/internal/httputil/httputil.go b/integration/internal/httputil/httputil.go index 486e02b63..e0c5b4a02 100644 --- a/integration/internal/httputil/httputil.go +++ b/integration/internal/httputil/httputil.go @@ -1,3 +1,4 @@ +// Package httputil has helper functions for working with HTTP. package httputil import ( @@ -11,6 +12,8 @@ type localRoundTripper struct { portToAddr map[string]string } +// NewLocalRoundTripper creates a new http.RoundTripper which routes localhost traffic to the remote destinations +// defined by `portToAddr`. func NewLocalRoundTripper(underlying http.RoundTripper, portToAddr map[string]string) http.RoundTripper { lrt := &localRoundTripper{underlying: underlying, portToAddr: portToAddr} return lrt diff --git a/integration/main_test.go b/integration/main_test.go index fafcc77b2..212a424f2 100644 --- a/integration/main_test.go +++ b/integration/main_test.go @@ -15,8 +15,6 @@ import ( "github.com/rs/zerolog/log" ) -const localHTTPSPort = 9443 - var ( mainCtx context.Context testcluster *cluster.Cluster @@ -39,8 +37,7 @@ func TestMain(m *testing.M) { mainCtx, clearTimeout = context.WithTimeout(mainCtx, time.Minute*10) defer clearTimeout() - _, mainTestFilePath, _, _ := runtime.Caller(0) - testcluster = cluster.New(filepath.Dir(mainTestFilePath)) + testcluster = cluster.New(getBaseDir()) if err := testcluster.Setup(mainCtx); err != nil { log.Fatal().Err(err).Send() } @@ -50,3 +47,9 @@ func TestMain(m *testing.M) { gocleanup.Cleanup() os.Exit(status) } + +// getBaseDir returns the directory that main_test resides in +func getBaseDir() string { + _, file, _, _ := runtime.Caller(0) //nolint + return filepath.Dir(file) +}