Skip to content

Commit fedff95

Browse files
committed
Re-factored e2e helper packages per commenter recommendation.
1 parent beee7c8 commit fedff95

File tree

9 files changed

+37
-35
lines changed

9 files changed

+37
-35
lines changed

test/e2e/deploy_app_toxi.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"os"
2727
"path/filepath"
2828
"runtime"
29-
"sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/helpers"
29+
"sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/toxiproxy"
3030
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
3131
"sigs.k8s.io/cluster-api/util"
3232
)
@@ -41,8 +41,8 @@ func DeployAppToxiSpec(ctx context.Context, inputGetter func() CommonSpecInput)
4141
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
4242
bootstrapClusterToxicName string
4343
cloudStackToxicName string
44-
bootstrapClusterToxiProxyContext *helpers.ToxiProxyContext
45-
cloudStackToxiProxyContext *helpers.ToxiProxyContext
44+
bootstrapClusterToxiProxyContext *toxiproxy.Context
45+
cloudStackToxiProxyContext *toxiproxy.Context
4646
appName = "httpd"
4747
appManifestPath = "data/fixture/sample-application.yaml"
4848
expectedHtmlPath = "data/fixture/expected-webpage.html"
@@ -66,14 +66,14 @@ func DeployAppToxiSpec(ctx context.Context, inputGetter func() CommonSpecInput)
6666
Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion))
6767

6868
// Set up a toxiProxy for bootstrap server.
69-
bootstrapClusterToxiProxyContext = helpers.SetupForToxiProxyTestingBootstrapCluster(input.BootstrapClusterProxy, clusterName)
69+
bootstrapClusterToxiProxyContext = toxiproxy.SetupForToxiProxyTestingBootstrapCluster(input.BootstrapClusterProxy, clusterName)
7070
const ToxicLatencyMs = 100
7171
const ToxicJitterMs = 100
7272
const ToxicToxicity = 1
7373
bootstrapClusterToxicName = bootstrapClusterToxiProxyContext.AddLatencyToxic(ToxicLatencyMs, ToxicJitterMs, ToxicToxicity, false)
7474

7575
// Set up a toxiProxy for CloudStack
76-
cloudStackToxiProxyContext = helpers.SetupForToxiProxyTestingACS(
76+
cloudStackToxiProxyContext = toxiproxy.SetupForToxiProxyTestingACS(
7777
ctx,
7878
clusterName,
7979
input.BootstrapClusterProxy,
@@ -154,9 +154,9 @@ func DeployAppToxiSpec(ctx context.Context, inputGetter func() CommonSpecInput)
154154

155155
// Tear down the ToxiProxies
156156
cloudStackToxiProxyContext.RemoveToxic(cloudStackToxicName)
157-
helpers.TearDownToxiProxyACS(ctx, input.BootstrapClusterProxy, cloudStackToxiProxyContext)
157+
toxiproxy.TearDownToxiProxyACS(ctx, input.BootstrapClusterProxy, cloudStackToxiProxyContext)
158158

159159
bootstrapClusterToxiProxyContext.RemoveToxic(bootstrapClusterToxicName)
160-
helpers.TearDownToxiProxyBootstrap(bootstrapClusterToxiProxyContext)
160+
toxiproxy.TearDownToxiProxyBootstrap(bootstrapClusterToxiProxyContext)
161161
})
162162
}

test/e2e/e2e_suite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"os"
2626
"path/filepath"
2727
go_runtime "runtime"
28-
"sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/helpers"
28+
"sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/toxiproxy"
2929
"strings"
3030
"testing"
3131
"time"
@@ -122,7 +122,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
122122
// Toxiproxy running in a docker container requires docker host networking, only available in linux.
123123
if go_runtime.GOOS == "linux" {
124124
By("Launching Toxiproxy Server")
125-
Expect(helpers.ToxiProxyServerExec(ctx)).To(Succeed())
125+
Expect(toxiproxy.ServerExec(ctx)).To(Succeed())
126126
}
127127

128128
if clusterctlConfig == "" {
@@ -180,7 +180,7 @@ var _ = SynchronizedAfterSuite(func() {
180180

181181
if go_runtime.GOOS == "linux" {
182182
By("Killing Toxiproxy Server")
183-
Expect(helpers.ToxiProxyServerKill(ctx)).To(Succeed())
183+
Expect(toxiproxy.ServerKill(ctx)).To(Succeed())
184184
}
185185
})
186186

File renamed without changes.

test/e2e/helpers/kubeconfig.go renamed to test/e2e/kubeconfig_helper/kubeconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package helpers
17+
package kubeconfig_helper
1818

1919
import (
2020
"errors"

test/e2e/helpers/kubeconfig_test.go renamed to test/e2e/kubeconfig_helper/kubeconfig_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package helpers_test
17+
package kubeconfig_helper_test
1818

1919
import (
2020
. "github.com/onsi/ginkgo"
2121
. "github.com/onsi/gomega"
2222
"io/ioutil"
23-
"sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/helpers"
23+
"sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/kubeconfig_helper"
2424
)
2525

2626
var _ = Describe("Test kubeconfig helper methods", func() {
2727
It("should work", func() {
28-
kubeconfig := helpers.NewKubeconfig()
28+
kubeconfig := kubeconfig_helper.NewKubeconfig()
2929

3030
var kubeconfigPath string = "./data/kubeconfig"
3131
var unmodifiedKubeconfigPath string = "/tmp/unmodifiedKubeconfig"

test/e2e/helpers/suite_test.go renamed to test/e2e/kubeconfig_helper/suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package helpers_test
1+
package kubeconfig_helper_test
22

33
import (
44
"testing"
@@ -9,5 +9,5 @@ import (
99

1010
func TestHelpers(t *testing.T) {
1111
RegisterFailHandler(Fail)
12-
RunSpecs(t, "Helpers Suite")
12+
RunSpecs(t, "Kubeconfig Helpers Suite")
1313
}

test/e2e/network_interruption_toxi.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
corev1 "k8s.io/api/core/v1"
3030
"k8s.io/utils/pointer"
3131
"sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/helpers"
32+
"sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/toxiproxy"
3233
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
3334
"sigs.k8s.io/cluster-api/util"
3435
)
@@ -41,7 +42,7 @@ func NetworkInterruptionToxiSpec(ctx context.Context, inputGetter func() CommonS
4142
namespace *corev1.Namespace
4243
cancelWatches context.CancelFunc
4344
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
44-
cloudStackToxiProxyContext *helpers.ToxiProxyContext
45+
cloudStackToxiProxyContext *toxiproxy.Context
4546
clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6))
4647
networkInterruptorShutdownChannel = make(chan bool, 2)
4748
)
@@ -59,7 +60,7 @@ func NetworkInterruptionToxiSpec(ctx context.Context, inputGetter func() CommonS
5960
Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion))
6061

6162
// Set up a toxiProxy for CloudStack
62-
cloudStackToxiProxyContext = helpers.SetupForToxiProxyTestingACS(
63+
cloudStackToxiProxyContext = toxiproxy.SetupForToxiProxyTestingACS(
6364
ctx,
6465
clusterName,
6566
input.BootstrapClusterProxy,
@@ -121,11 +122,11 @@ func NetworkInterruptionToxiSpec(ctx context.Context, inputGetter func() CommonS
121122
dumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
122123

123124
// Tear down the ToxiProxies
124-
helpers.TearDownToxiProxyACS(ctx, input.BootstrapClusterProxy, cloudStackToxiProxyContext)
125+
toxiproxy.TearDownToxiProxyACS(ctx, input.BootstrapClusterProxy, cloudStackToxiProxyContext)
125126
})
126127
}
127128

128-
func networkInterruptor(toxiProxyContext *helpers.ToxiProxyContext, shutdownChannel chan bool) {
129+
func networkInterruptor(toxiProxyContext *toxiproxy.Context, shutdownChannel chan bool) {
129130
// Wait for ApplyClusterTemplateAndWait() to make some progress
130131
helpers.InterruptibleSleep(15*time.Second, time.Second, shutdownChannel)
131132

test/e2e/helpers/toxiProxy.go renamed to test/e2e/toxiproxy/toxiProxy.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package helpers
17+
package toxiproxy
1818

1919
import (
2020
"context"
@@ -29,13 +29,14 @@ import (
2929
toxiproxyapi "github.com/Shopify/toxiproxy/v2/client"
3030
. "github.com/onsi/gomega"
3131
corev1 "k8s.io/api/core/v1"
32+
"sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/kubeconfig_helper"
3233
"sigs.k8s.io/cluster-api/test/framework"
3334
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
3435
"sigs.k8s.io/cluster-api/test/framework/exec"
3536
"sigs.k8s.io/controller-runtime/pkg/client"
3637
)
3738

38-
func ToxiProxyServerExec(ctx context.Context) error {
39+
func ServerExec(ctx context.Context) error {
3940
execArgs := []string{"run", "-d", "--name=capc-e2e-toxiproxy", "--net=host", "--rm", "ghcr.io/shopify/toxiproxy"}
4041
runCmd := exec.NewCommand(
4142
exec.WithCommand("docker"),
@@ -48,7 +49,7 @@ func ToxiProxyServerExec(ctx context.Context) error {
4849
return err
4950
}
5051

51-
func ToxiProxyServerKill(ctx context.Context) error {
52+
func ServerKill(ctx context.Context) error {
5253
execArgs := []string{"stop", "capc-e2e-toxiproxy"}
5354
runCmd := exec.NewCommand(
5455
exec.WithCommand("docker"),
@@ -58,17 +59,17 @@ func ToxiProxyServerKill(ctx context.Context) error {
5859
return err
5960
}
6061

61-
type ToxiProxyContext struct {
62+
type Context struct {
6263
KubeconfigPath string
6364
Secret corev1.Secret
6465
ClusterProxy framework.ClusterProxy
6566
ToxiProxy *toxiproxyapi.Proxy
6667
ConfigPath string
6768
}
6869

69-
func SetupForToxiProxyTestingBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, clusterName string) *ToxiProxyContext {
70+
func SetupForToxiProxyTestingBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, clusterName string) *Context {
7071
// Read/parse the actual kubeconfig for the cluster
71-
kubeConfig := NewKubeconfig()
72+
kubeConfig := kubeconfig_helper.NewKubeconfig()
7273
unproxiedKubeconfigPath := bootstrapClusterProxy.GetKubeconfigPath()
7374
err := kubeConfig.Load(unproxiedKubeconfigPath)
7475
Expect(err).To(BeNil())
@@ -112,14 +113,14 @@ func SetupForToxiProxyTestingBootstrapCluster(bootstrapClusterProxy framework.Cl
112113
framework.WithMachineLogCollector(framework.DockerLogCollector{}),
113114
)
114115

115-
return &ToxiProxyContext{
116+
return &Context{
116117
KubeconfigPath: toxiProxyKubeconfigPath,
117118
ClusterProxy: toxiproxyBootstrapClusterProxy,
118119
ToxiProxy: proxy,
119120
}
120121
}
121122

122-
func TearDownToxiProxyBootstrap(toxiProxyContext *ToxiProxyContext) {
123+
func TearDownToxiProxyBootstrap(toxiProxyContext *Context) {
123124
// Tear down the proxy
124125
err := toxiProxyContext.ToxiProxy.Delete()
125126
Expect(err).To(BeNil())
@@ -129,12 +130,12 @@ func TearDownToxiProxyBootstrap(toxiProxyContext *ToxiProxyContext) {
129130
Expect(err).To(BeNil())
130131
}
131132

132-
func (tp *ToxiProxyContext) RemoveToxic(toxicName string) {
133+
func (tp *Context) RemoveToxic(toxicName string) {
133134
err := tp.ToxiProxy.RemoveToxic(toxicName)
134135
Expect(err).To(BeNil())
135136
}
136137

137-
func (tp *ToxiProxyContext) AddLatencyToxic(latencyMs int, jitterMs int, toxicity float32, upstream bool) string {
138+
func (tp *Context) AddLatencyToxic(latencyMs int, jitterMs int, toxicity float32, upstream bool) string {
138139
stream := "downstream"
139140
if upstream == true {
140141
stream = "upstream"
@@ -150,15 +151,15 @@ func (tp *ToxiProxyContext) AddLatencyToxic(latencyMs int, jitterMs int, toxicit
150151
return toxicName
151152
}
152153

153-
func (tp *ToxiProxyContext) Disable() {
154+
func (tp *Context) Disable() {
154155
tp.ToxiProxy.Disable()
155156
}
156157

157-
func (tp *ToxiProxyContext) Enable() {
158+
func (tp *Context) Enable() {
158159
tp.ToxiProxy.Enable()
159160
}
160161

161-
func SetupForToxiProxyTestingACS(ctx context.Context, clusterName string, clusterProxy framework.ClusterProxy, e2eConfig *clusterctl.E2EConfig, configPath string) *ToxiProxyContext {
162+
func SetupForToxiProxyTestingACS(ctx context.Context, clusterName string, clusterProxy framework.ClusterProxy, e2eConfig *clusterctl.E2EConfig, configPath string) *Context {
162163
// Get the cloud-config secret that CAPC will use to access CloudStack
163164
fdEndpointSecretObjectKey := client.ObjectKey{
164165
Namespace: e2eConfig.GetVariable("CLOUDSTACK_FD1_SECRET_NAMESPACE"),
@@ -209,14 +210,14 @@ func SetupForToxiProxyTestingACS(ctx context.Context, clusterName string, cluste
209210
editConfigFile(newConfigFilePath, configPath, "CLOUDSTACK_FD1_SECRET_NAME", toxiProxyFdEndpointSecret.Name)
210211

211212
// Return a context
212-
return &ToxiProxyContext{
213+
return &Context{
213214
Secret: toxiProxyFdEndpointSecret,
214215
ToxiProxy: proxy,
215216
ConfigPath: newConfigFilePath,
216217
}
217218
}
218219

219-
func TearDownToxiProxyACS(ctx context.Context, clusterProxy framework.ClusterProxy, toxiProxyContext *ToxiProxyContext) {
220+
func TearDownToxiProxyACS(ctx context.Context, clusterProxy framework.ClusterProxy, toxiProxyContext *Context) {
220221
// Tear down the proxy
221222
err := toxiProxyContext.ToxiProxy.Delete()
222223
Expect(err).To(BeNil())

0 commit comments

Comments
 (0)