Skip to content

Commit 24ac28a

Browse files
committed
e2e: test mysql
1 parent 0cc9848 commit 24ac28a

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

e2e/volumestatefulset/volumestatefulset_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ func TestVolumeStatefulSet(t *testing.T) {
3030
runtimeHandler, err := manifest.RuntimeHandler(platform)
3131
require.NoError(t, err)
3232

33+
// We have two resource sets for testing volumes: VolumeStatefulSet and MySQL. The former is
34+
// designed for testing, while the latter is a demo artifact we include in releases. The
35+
// functional tests below mostly use the VolumeStatefulSet, but we include MySQL and some basic
36+
// checks as a smoke test.
3337
resources := kuberesource.VolumeStatefulSet()
38+
resources = append(resources, kuberesource.MySQL()...)
3439

3540
coordinator := kuberesource.CoordinatorBundle()
3641

@@ -95,6 +100,32 @@ func TestVolumeStatefulSet(t *testing.T) {
95100
require.NoError(err, "stdout: %s, stderr: %s", stdOut, stdErr)
96101
require.Equal("test\n", stdOut)
97102
})
103+
104+
t.Run("MySQL demo works", func(t *testing.T) {
105+
const (
106+
mysqlBackend = "mysql-backend"
107+
mysqlClient = "mysql-client"
108+
)
109+
110+
require := require.New(t)
111+
112+
// The MySQL server runs initialization on first boot if the volume is empty, which takes
113+
// a considerable amount of time. Combined with a medium sized image and docker hubs slow
114+
// pull bandwidth, it can take quite some time until the server comes up.
115+
ctx, cancel := context.WithTimeout(t.Context(), ct.FactorPlatformTimeout(5*time.Minute))
116+
defer cancel()
117+
118+
require.NoError(ct.Kubeclient.WaitForStatefulSet(ctx, ct.Namespace, mysqlBackend))
119+
require.NoError(ct.Kubeclient.WaitForDeployment(ctx, ct.Namespace, mysqlClient))
120+
121+
pods, err := ct.Kubeclient.PodsFromDeployment(ctx, ct.Namespace, mysqlClient)
122+
require.NoError(err)
123+
require.Len(pods, 1)
124+
command := []string{"/bin/sh", "-c", `mysql -h 127.137.0.1 -u root -D my_db -e "SELECT * FROM my_table;"`}
125+
stdout, stderr, err := ct.Kubeclient.ExecRetry(ctx, ct.Namespace, pods[0].Name, mysqlClient, command, time.Second)
126+
require.NoErrorf(err, "mysql command failed - stderr:\n%s", stderr)
127+
require.Contains(stdout, "uuid")
128+
})
98129
}
99130

100131
func TestMain(m *testing.M) {

0 commit comments

Comments
 (0)