Skip to content

Commit

Permalink
[testing-framework] Make golangci happy
Browse files Browse the repository at this point in the history
  • Loading branch information
hoegaarden committed Dec 6, 2019
1 parent 8a6a7f2 commit d492d7a
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pkg/builder/builder_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/internal/testing/integration/addr"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/internal/testing/integration/addr"
)

func TestBuilder(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/internal/testing/integration/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type APIServer struct {
// APIServer struct (e.g. "--cert-dir={{ .Dir }}").
// Those templates will be evaluated after the defaulting of the APIServer's
// fields has already happened and just before the binary actually gets
// started. Thus you have access to caluclated fields like `URL` and others.
// started. Thus you have access to calculated fields like `URL` and others.
//
// If not specified, the minimal set of arguments to run the APIServer will
// be used.
Expand Down Expand Up @@ -131,6 +131,6 @@ func (s *APIServer) Stop() error {
// APIServerDefaultArgs exposes the default args for the APIServer so that you
// can use those to append your own additional arguments.
//
// The internal default arguments are explicitely copied here, we don't want to
// The internal default arguments are explicitly copied here, we don't want to
// allow users to change the internal ones.
var APIServerDefaultArgs = append([]string{}, internal.APIServerDefaultArgs...)
4 changes: 2 additions & 2 deletions pkg/internal/testing/integration/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Etcd struct {
// struct (e.g. "--data-dir={{ .Dir }}").
// Those templates will be evaluated after the defaulting of the Etcd's
// fields has already happened and just before the binary actually gets
// started. Thus you have access to caluclated fields like `URL` and others.
// started. Thus you have access to calculated fields like `URL` and others.
//
// If not specified, the minimal set of arguments to run the Etcd will be
// used.
Expand Down Expand Up @@ -109,6 +109,6 @@ func (e *Etcd) Stop() error {
// EtcdDefaultArgs exposes the default args for Etcd so that you
// can use those to append your own additional arguments.
//
// The internal default arguments are explicitely copied here, we don't want to
// The internal default arguments are explicitly copied here, we don't want to
// allow users to change the internal ones.
var EtcdDefaultArgs = append([]string{}, internal.EtcdDefaultArgs...)
4 changes: 2 additions & 2 deletions pkg/internal/testing/integration/internal/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func isSecureScheme(scheme string) bool {
return false
}

func GetEtcdStartMessage(listenUrl url.URL) string {
if isSecureScheme(listenUrl.Scheme) {
func GetEtcdStartMessage(listenURL url.URL) string {
if isSecureScheme(listenURL.Scheme) {
// https://github.com/coreos/etcd/blob/a7f1fbe00ec216fcb3a1919397a103b41dca8413/embed/serve.go#L167
return "serving client requests on "
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration_tests
package integrationtests

import (
. "github.com/onsi/ginkgo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ framework.
This file's only purpose is to make godep happy.
*/
package integration_tests
package integrationtests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration_tests
package integrationtests

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration_tests
package integrationtests

import (
. "github.com/onsi/ginkgo"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration_tests
package integrationtests

import (
"fmt"
Expand Down Expand Up @@ -132,8 +132,8 @@ var _ = Describe("The Testing Framework", func() {
b.Time("lifecycle", func() {
controlPlane = &integration.ControlPlane{}

controlPlane.Start()
controlPlane.Stop()
Expect(controlPlane.Start()).To(Succeed())
Expect(controlPlane.Stop()).To(Succeed())
})
}, 10)
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/internal/testing/integration/internal/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ProcessState struct {
// HealthCheckEndpoint.
// If left empty it will default to 100 Milliseconds.
HealthCheckPollInterval time.Duration
// StartMessage is the message to wait for on stderr. If we recieve this
// StartMessage is the message to wait for on stderr. If we receive this
// message, we assume the process is ready to operate. Ignored if
// HealthCheckEndpoint is specified.
//
Expand All @@ -57,7 +57,7 @@ type DefaultedProcessInput struct {

func DoDefaulting(
name string,
listenUrl *url.URL,
listenURL *url.URL,
dir string,
path string,
startTimeout time.Duration,
Expand All @@ -70,7 +70,7 @@ func DoDefaulting(
StopTimeout: stopTimeout,
}

if listenUrl == nil {
if listenURL == nil {
port, host, err := addr.Suggest()
if err != nil {
return DefaultedProcessInput{}, err
Expand All @@ -80,7 +80,7 @@ func DoDefaulting(
Host: net.JoinHostPort(host, strconv.Itoa(port)),
}
} else {
defaults.URL = *listenUrl
defaults.URL = *listenURL
}

if dir == "" {
Expand Down
26 changes: 15 additions & 11 deletions pkg/internal/testing/integration/internal/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
. "sigs.k8s.io/controller-runtime/pkg/internal/testing/integration/internal"
)

const (
healthURLPath = "/healthz"
)

var _ = Describe("Start method", func() {
var (
processState *ProcessState
Expand Down Expand Up @@ -50,11 +54,11 @@ var _ = Describe("Start method", func() {

Context("when the healthcheck returns ok", func() {
BeforeEach(func() {
server.RouteToHandler("GET", "/healthz", ghttp.RespondWith(http.StatusOK, ""))
server.RouteToHandler("GET", healthURLPath, ghttp.RespondWith(http.StatusOK, ""))
})

It("hits the endpoint, and successfully starts", func() {
processState.HealthCheckEndpoint = "/healthz"
processState.HealthCheckEndpoint = healthURLPath
processState.StartTimeout = 100 * time.Millisecond
processState.URL = getServerURL(server)

Expand All @@ -67,10 +71,10 @@ var _ = Describe("Start method", func() {

Context("when the healthcheck always returns failure", func() {
BeforeEach(func() {
server.RouteToHandler("GET", "/healthz", ghttp.RespondWith(http.StatusInternalServerError, ""))
server.RouteToHandler("GET", healthURLPath, ghttp.RespondWith(http.StatusInternalServerError, ""))
})
It("returns a timeout error and stops health API checker", func() {
processState.HealthCheckEndpoint = "/healthz"
processState.HealthCheckEndpoint = healthURLPath
processState.StartTimeout = 500 * time.Millisecond
processState.URL = getServerURL(server)

Expand All @@ -90,7 +94,7 @@ var _ = Describe("Start method", func() {
})

It("returns a timeout error", func() {
processState.HealthCheckEndpoint = "/healthz"
processState.HealthCheckEndpoint = healthURLPath
processState.StartTimeout = 500 * time.Millisecond

port, host, err := addr.Suggest()
Expand All @@ -117,7 +121,7 @@ var _ = Describe("Start method", func() {
})

It("hits the endpoint repeatedly, and successfully starts", func() {
processState.HealthCheckEndpoint = "/healthz"
processState.HealthCheckEndpoint = healthURLPath
processState.StartTimeout = 20 * time.Second
processState.URL = getServerURL(server)

Expand All @@ -144,7 +148,7 @@ var _ = Describe("Start method", func() {
})

It("hits the endpoint in the configured interval", func() {
processState.HealthCheckEndpoint = "/healthz"
processState.HealthCheckEndpoint = healthURLPath
processState.StartTimeout = 3 * processState.HealthCheckPollInterval
processState.URL = getServerURL(server)

Expand All @@ -170,21 +174,21 @@ var _ = Describe("Start method", func() {
})

Context("when the command cannot be started", func() {
var err error

BeforeEach(func() {
processState = &ProcessState{}
processState.Path = "/nonexistent"

err = processState.Start(nil, nil)
})

It("propagates the error", func() {
err := processState.Start(nil, nil)

Expect(os.IsNotExist(err)).To(BeTrue())
})

Context("but Stop() is called on it", func() {
It("does not panic", func() {
processState.Start(nil, nil)

stoppingFailedProcess := func() {
Expect(processState.Stop()).To(Succeed())
}
Expand Down

0 comments on commit d492d7a

Please sign in to comment.