Skip to content

Commit

Permalink
cluster/container: update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyass committed Jul 27, 2021
1 parent d202371 commit 38f3969
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 53 deletions.
42 changes: 1 addition & 41 deletions cluster/container/init_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
},
MysqlVersion: "5.7",
MysqlOpts: mysqlv1alpha1.MysqlOpts{
RootHost: "127.0.0.1",
InitTokuDB: false,
},
},
Expand All @@ -54,11 +55,6 @@ var (
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
},
{
Name: utils.ConfMapVolumeName,
MountPath: utils.MyCnfMountPath,
SubPath: "my.cnf",
},
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
Expand Down Expand Up @@ -100,42 +96,6 @@ var (
},
},
},
{
Name: "MYSQL_DATABASE",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: sctName,
},
Key: "mysql-database",
Optional: &optTrue,
},
},
},
{
Name: "MYSQL_USER",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: sctName,
},
Key: "mysql-user",
Optional: &optTrue,
},
},
},
{
Name: "MYSQL_PASSWORD",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: sctName,
},
Key: "mysql-password",
Optional: &optTrue,
},
},
},
}
initMysqlCase = EnsureContainer("init-mysql", &testInitMysqlCluster)
)
Expand Down
49 changes: 48 additions & 1 deletion cluster/container/init_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package container

import (
"fmt"
"strconv"
"testing"

Expand All @@ -32,11 +33,13 @@ import (
var (
defeatCount int32 = 1
electionTimeout int32 = 5
replicas int32 = 3
initSidecarMysqlCluster = mysqlv1alpha1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "sample",
},
Spec: mysqlv1alpha1.ClusterSpec{
Replicas: &replicas,
PodSpec: mysqlv1alpha1.PodSpec{
SidecarImage: "sidecar image",
Resources: corev1.ResourceRequirements{
Expand Down Expand Up @@ -80,6 +83,14 @@ var (
Name: "SERVICE_NAME",
Value: "sample-mysql",
},
{
Name: "STATEFULSET_NAME",
Value: "sample-mysql",
},
{
Name: "REPLICAS",
Value: fmt.Sprintf("%d", *testInitSidecarCluster.Spec.Replicas),
},
{
Name: "ADMIT_DEFEAT_HEARBEAT_COUNT",
Value: strconv.Itoa(int(*testInitSidecarCluster.Spec.XenonOpts.AdmitDefeatHearbeatCount)),
Expand All @@ -104,6 +115,42 @@ var (
},
},
},
{
Name: "MYSQL_DATABASE",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: sctName,
},
Key: "mysql-database",
Optional: &optTrue,
},
},
},
{
Name: "MYSQL_USER",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: sctName,
},
Key: "mysql-user",
Optional: &optTrue,
},
},
},
{
Name: "MYSQL_PASSWORD",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: sctName,
},
Key: "mysql-password",
Optional: &optTrue,
},
},
},
{
Name: "MYSQL_REPL_USER",
ValueFrom: &corev1.EnvVarSource{
Expand Down Expand Up @@ -228,7 +275,7 @@ func TestGetInitSidecarEnvVar(t *testing.T) {
Cluster: &testToKuDBMysqlCluster,
}
tokudbCase := EnsureContainer("init-sidecar", &testTokuDBCluster)
testTokuDBEnv := make([]corev1.EnvVar, 13)
testTokuDBEnv := make([]corev1.EnvVar, 18)
copy(testTokuDBEnv, defaultInitSidecarEnvs)
testTokuDBEnv = append(testTokuDBEnv, corev1.EnvVar{
Name: "INIT_TOKUDB",
Expand Down
11 changes: 3 additions & 8 deletions cluster/container/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestGetMysqlLivenessProbe(t *testing.T) {
livenessProbe := &corev1.Probe{
Handler: corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{"sh", "-c", "mysqladmin ping -uroot -p${MYSQL_ROOT_PASSWORD}"},
Command: []string{"sh", "-c", "mysqladmin --defaults-file=/etc/mysql/client.conf ping"},
},
},
InitialDelaySeconds: 30,
Expand All @@ -123,7 +123,7 @@ func TestGetMysqlReadinessProbe(t *testing.T) {
readinessProbe := &corev1.Probe{
Handler: corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{"sh", "-c", `mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "SELECT 1"`},
Command: []string{"sh", "-c", `test $(mysql --defaults-file=/etc/mysql/client.conf -NB -e "SELECT 1") -eq 1`},
},
},
InitialDelaySeconds: 10,
Expand All @@ -139,12 +139,7 @@ func TestGetMysqlVolumeMounts(t *testing.T) {
volumeMounts := []corev1.VolumeMount{
{
Name: "conf",
MountPath: "/etc/mysql/conf.d",
},
{
Name: "config-map",
MountPath: "/etc/mysql/my.cnf",
SubPath: "my.cnf",
MountPath: "/etc/mysql",
},
{
Name: "data",
Expand Down
9 changes: 6 additions & 3 deletions cluster/container/xenon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ func TestGetXenonLifecycle(t *testing.T) {
lifecycle := &corev1.Lifecycle{
PostStart: &corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{"sh", "-c",
"until (xenoncli xenon ping && xenoncli cluster add sample-mysql-0.sample-mysql.default:8801) > /dev/null 2>&1; do sleep 2; done",
},
Command: []string{"sh", "-c", "/scripts/post-start.sh"},
},
},
PreStop: &corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{"sh", "-c", "/scripts/pre-stop.sh"},
},
},
}
Expand Down

0 comments on commit 38f3969

Please sign in to comment.