-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
related to #533 I enhanced terratest extensions and utils with a function that can run a command in busybox and a function that can read json output from test app. Thanks to this I can automate tests from local playground. Besides the test itself, I had to extend `WithTestApp(uiMessage string)` with the message argument and bump the subinfo from `4.0.6` to `5.0.1`. Tests are asserting local targets which are digged after `WaitForAppIsRunning` pass, otherwise digged localtargets will be `[]string{}`. I also implemented InstanceStatus, which is a functionality that takes all available instance data, such as Dig, endpoint status, CoreDNS IP etc... The functionality is useful for tracing errors and possible assertions. Signed-off-by: kuritka <kuritka@gmail.com>
- Loading branch information
Showing
6 changed files
with
298 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: k8gb.absa.oss/v1beta1 | ||
kind: Gslb | ||
metadata: | ||
name: test-gslb | ||
spec: | ||
ingress: | ||
rules: | ||
- host: playground-failover.cloud.example.com | ||
http: | ||
paths: | ||
- backend: | ||
serviceName: frontend-podinfo # Gslb should reflect Healthy status and create associated DNS records | ||
servicePort: http | ||
path: / | ||
strategy: | ||
type: failover | ||
primaryGeoTag: "eu" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2021 The k8gb Contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic | ||
*/ | ||
package test | ||
|
||
import ( | ||
"k8gbterratest/utils" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestFailoverPlayground is equal to k8gb failover test running on local playground. | ||
// see: https://github.com/k8gb-io/k8gb/blob/master/docs/local.md#failover | ||
func TestFailoverPlayground(t *testing.T) { | ||
t.Parallel() | ||
const host = "playground-failover.cloud.example.com" | ||
const gslbPath = "../examples/failover-playground.yaml" | ||
const euGeoTag = "eu" | ||
const usGeoTag = "us" | ||
|
||
instanceEU, err := utils.NewWorkflow(t, "k3d-test-gslb1", 5053). | ||
WithGslb(gslbPath, host). | ||
WithTestApp(euGeoTag). | ||
Start() | ||
require.NoError(t, err) | ||
defer instanceEU.Kill() | ||
instanceUS, err := utils.NewWorkflow(t, "k3d-test-gslb2", 5054). | ||
WithGslb(gslbPath, host). | ||
WithTestApp(usGeoTag). | ||
Start() | ||
require.NoError(t, err) | ||
defer instanceUS.Kill() | ||
|
||
actAndAssert := func(test, geoTag string, localTargets []string) { | ||
// waiting for DNS sync | ||
err = instanceEU.WaitForExpected(localTargets) | ||
require.NoError(t, err) | ||
err = instanceUS.WaitForExpected(localTargets) | ||
require.NoError(t, err) | ||
// hit testApp from both clusters | ||
httpResult := instanceEU.HitTestApp() | ||
assert.Equal(t, geoTag, httpResult.Message) | ||
httpResult = instanceUS.HitTestApp() | ||
assert.Equal(t, geoTag, httpResult.Message) | ||
} | ||
|
||
t.Run("failover on two concurrent clusters with TestApp running", func(t *testing.T) { | ||
err = instanceEU.WaitForAppIsRunning() | ||
require.NoError(t, err) | ||
err = instanceUS.WaitForAppIsRunning() | ||
require.NoError(t, err) | ||
}) | ||
|
||
euLocalTargets := instanceEU.GetLocalTargets() | ||
usLocalTargets := instanceUS.GetLocalTargets() | ||
|
||
t.Run("stop podinfo on eu cluster", func(t *testing.T) { | ||
instanceEU.StopTestApp() | ||
actAndAssert(t.Name(), usGeoTag, usLocalTargets) | ||
}) | ||
|
||
t.Run("start podinfo again on eu cluster", func(t *testing.T) { | ||
instanceEU.StartTestApp() | ||
actAndAssert(t.Name(), euGeoTag, euLocalTargets) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.