Skip to content

Commit

Permalink
test: fix make test fail by init sidercar test radondb#256
Browse files Browse the repository at this point in the history
[summary]
fix bug of make test fail:
```
--- FAIL: TestGetInitSidecarEnvVar (0.00s)
    init_sidecar_test.go:297:
        	Error Trace:	init_sidecar_test.go:297
        	Error:      	Not equal:
        	            	expected: []v1.EnvVar{v1.EnvVar{Name:"POD_HOSTNAME", Value:"", ValueFrom:(*v1.EnvVarSource)(0x29f1540)}, v1.EnvVar{Name:"NAMESPACE", Value:"", ValueFrom:(*v1.EnvVarSource)(nil)},
...
...
        	            	actual  : []v1.EnvVar{v1.EnvVar{Name:"CONTAINER_TYPE", Value:"init-sidecar", ValueFrom:(*v1.EnvVarSource)(nil)}, v1.EnvVar{Name:"POD_HOSTNAME", Value:"", ValueFrom:(*v1.EnvVarSource)(0xc0004a87c0)},
...
...
```
related issue: radondb#116
First meet in commit: bd4fbd8
First error in commit: 46c0ce7

[testcase]
cluster/container/init_sidecar_test.go
  • Loading branch information
hustjieke committed Oct 12, 2021
1 parent 934c703 commit be9b108
Showing 1 changed file with 71 additions and 1 deletion.
72 changes: 71 additions & 1 deletion cluster/container/init_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ var (
Cluster: &initSidecarMysqlCluster,
}
defaultInitSidecarEnvs = []corev1.EnvVar{
{
Name: "CONTAINER_TYPE",
Value: utils.ContainerInitSidecarName,
},
{
Name: "POD_HOSTNAME",
ValueFrom: &corev1.EnvVarSource{
Expand Down Expand Up @@ -304,14 +308,80 @@ func TestGetInitSidecarEnvVar(t *testing.T) {
Cluster: &testToKuDBMysqlCluster,
}
tokudbCase := EnsureContainer("init-sidecar", &testTokuDBCluster)
testTokuDBEnv := make([]corev1.EnvVar, 18)
testTokuDBEnv := make([]corev1.EnvVar, len(defaultInitSidecarEnvs))
copy(testTokuDBEnv, defaultInitSidecarEnvs)
testTokuDBEnv = append(testTokuDBEnv, corev1.EnvVar{
Name: "INIT_TOKUDB",
Value: "1",
})
assert.Equal(t, testTokuDBEnv, tokudbCase.Env)
}
// BackupSecretName not empty
{
testBackupMysqlCluster := initSidecarMysqlCluster
testBackupMysqlCluster.Spec.BackupSecretName = "backup-secret"
testBackupMysqlClusterWraper := cluster.Cluster{
Cluster: &testBackupMysqlCluster,
}
BackupCase := EnsureContainer("init-sidecar", &testBackupMysqlClusterWraper)
testBackupEnv := make([]corev1.EnvVar, len(defaultInitSidecarEnvs))
copy(testBackupEnv, defaultInitSidecarEnvs)
testBackupEnv = append(testBackupEnv,
corev1.EnvVar{
Name: "S3_ENDPOINT",

ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: testBackupMysqlClusterWraper.Spec.BackupSecretName,
},
Key: "s3-endpoint",
Optional: &optFalse,
},
},
},
corev1.EnvVar{
Name: "S3_ACCESSKEY",

ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: testBackupMysqlClusterWraper.Spec.BackupSecretName,
},
Key: "s3-access-key",
Optional: &optTrue,
},
},
},
corev1.EnvVar{
Name: "S3_SECRETKEY",

ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: testBackupMysqlClusterWraper.Spec.BackupSecretName,
},
Key: "s3-secret-key",
Optional: &optTrue,
},
},
},
corev1.EnvVar{
Name: "S3_BUCKET",

ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: testBackupMysqlClusterWraper.Spec.BackupSecretName,
},
Key: "s3-bucket",
Optional: &optTrue,
},
},
},
)
assert.Equal(t, testBackupEnv, BackupCase.Env)
}
}

func TestGetInitSidecarLifecycle(t *testing.T) {
Expand Down

0 comments on commit be9b108

Please sign in to comment.