diff --git a/.yamllint.yml b/.yamllint.yml index 5d83d60f3..e1ef06151 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -7,3 +7,6 @@ rules: allow-non-breakable-words: true allow-non-breakable-inline-mappings: true comments-indentation: disable + +ignore: + - resources.yaml \ No newline at end of file diff --git a/cmd/data-assert/go.mod b/tests/data-assert/go.mod similarity index 100% rename from cmd/data-assert/go.mod rename to tests/data-assert/go.mod diff --git a/cmd/data-assert/go.sum b/tests/data-assert/go.sum similarity index 100% rename from cmd/data-assert/go.sum rename to tests/data-assert/go.sum diff --git a/cmd/data-assert/main.go b/tests/data-assert/main.go similarity index 89% rename from cmd/data-assert/main.go rename to tests/data-assert/main.go index 85e5313fc..a8d19055f 100644 --- a/cmd/data-assert/main.go +++ b/tests/data-assert/main.go @@ -67,16 +67,22 @@ func genRedisDataCmd(cmd *cobra.Command, args []string) { ctx := context.Background() var rdb redis.UniversalClient + // Split host string by comma + hosts := strings.Split(host, ",") + for i := range hosts { + hosts[i] = strings.TrimSpace(hosts[i]) + } + switch mode { case "cluster": rdb = redis.NewClusterClient(&redis.ClusterOptions{ - Addrs: []string{host}, + Addrs: hosts, Password: pass, }) case "sentinel": rdb = redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: "mymaster", - SentinelAddrs: []string{host}, + SentinelAddrs: hosts, Password: pass, }) default: @@ -95,7 +101,7 @@ func genRedisDataCmd(cmd *cobra.Command, args []string) { return } } - fmt.Printf("successfully generated %d keys\n", totalKey) + fmt.Printf("[OK] successfully generated %d keys\n", totalKey) } // DataError represents data consistency check errors @@ -118,23 +124,29 @@ func chkRedisDataCmd(cmd *cobra.Command, args []string) { fmt.Printf("Error occurred during check: %v\n", err) os.Exit(1) } - fmt.Printf("Data consistency check passed! All %d keys exist\n", totalKey) + fmt.Printf("[OK] Data consistency check passed! All %d keys exist\n", totalKey) } func checkRedisData() error { ctx := context.Background() var rdb redis.UniversalClient + // Split host string by comma + hosts := strings.Split(host, ",") + for i := range hosts { + hosts[i] = strings.TrimSpace(hosts[i]) + } + switch mode { case "cluster": rdb = redis.NewClusterClient(&redis.ClusterOptions{ - Addrs: []string{host}, + Addrs: hosts, Password: pass, }) case "sentinel": rdb = redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: "mymaster", - SentinelAddrs: []string{host}, + SentinelAddrs: hosts, Password: pass, }) default: @@ -198,4 +210,5 @@ func genResourceYamlCmd(cmd *cobra.Command, args []string) { if err != nil { panic(err) } + fmt.Println("✅resources.yaml generated") } diff --git a/cmd/data-assert/resources.yaml b/tests/data-assert/resources.yaml similarity index 93% rename from cmd/data-assert/resources.yaml rename to tests/data-assert/resources.yaml index 054b2ab09..f7ed8a543 100644 --- a/cmd/data-assert/resources.yaml +++ b/tests/data-assert/resources.yaml @@ -74,16 +74,22 @@ data: ctx := context.Background() var rdb redis.UniversalClient + // Split host string by comma + hosts := strings.Split(host, ",") + for i := range hosts { + hosts[i] = strings.TrimSpace(hosts[i]) + } + switch mode { case "cluster": rdb = redis.NewClusterClient(&redis.ClusterOptions{ - Addrs: []string{host}, + Addrs: hosts, Password: pass, }) case "sentinel": rdb = redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: "mymaster", - SentinelAddrs: []string{host}, + SentinelAddrs: hosts, Password: pass, }) default: @@ -102,7 +108,7 @@ data: return } } - fmt.Printf("successfully generated %d keys\n", totalKey) + fmt.Printf("[OK] successfully generated %d keys\n", totalKey) } // DataError represents data consistency check errors @@ -125,23 +131,29 @@ data: fmt.Printf("Error occurred during check: %v\n", err) os.Exit(1) } - fmt.Printf("Data consistency check passed! All %d keys exist\n", totalKey) + fmt.Printf("[OK] Data consistency check passed! All %d keys exist\n", totalKey) } func checkRedisData() error { ctx := context.Background() var rdb redis.UniversalClient + // Split host string by comma + hosts := strings.Split(host, ",") + for i := range hosts { + hosts[i] = strings.TrimSpace(hosts[i]) + } + switch mode { case "cluster": rdb = redis.NewClusterClient(&redis.ClusterOptions{ - Addrs: []string{host}, + Addrs: hosts, Password: pass, }) case "sentinel": rdb = redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: "mymaster", - SentinelAddrs: []string{host}, + SentinelAddrs: hosts, Password: pass, }) default: @@ -205,6 +217,7 @@ data: if err != nil { panic(err) } + fmt.Println("✅resources.yaml generated") } go.mod: | diff --git a/cmd/data-assert/resources.yaml.tmpl b/tests/data-assert/resources.yaml.tmpl similarity index 100% rename from cmd/data-assert/resources.yaml.tmpl rename to tests/data-assert/resources.yaml.tmpl diff --git a/tests/e2e-chainsaw/v1beta2/redis-cluster-restart/chainsaw-test.yaml b/tests/e2e-chainsaw/v1beta2/redis-cluster-restart/chainsaw-test.yaml index d3e1b10a5..7725612c9 100644 --- a/tests/e2e-chainsaw/v1beta2/redis-cluster-restart/chainsaw-test.yaml +++ b/tests/e2e-chainsaw/v1beta2/redis-cluster-restart/chainsaw-test.yaml @@ -9,16 +9,18 @@ spec: - try: - apply: file: cluster.yaml + - apply: + file: ../../../data-assert/resources.yaml - assert: file: ready-cluster.yaml - - name: Try saving a key With Password + - name: Put data try: - script: timeout: 30s content: > - kubectl exec --namespace ${NAMESPACE} --container redis-cluster-v1beta2-leader redis-cluster-v1beta2-leader-0 -- - redis-cli -c set foo-0 bar-0 + kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert -- + bash -c "cd /go/src/data-assert && go run main.go gen-redis-data --host redis-cluster-v1beta2-leader.${NAMESPACE}.svc.cluster.local:6379 --mode cluster" check: (contains($stdout, 'OK')): true @@ -39,12 +41,12 @@ spec: - assert: file: ready-cluster.yaml - - name: Get key + - name: Assert data try: - script: timeout: 30s content: > - kubectl exec --namespace ${NAMESPACE} --container redis-cluster-v1beta2-leader redis-cluster-v1beta2-leader-0 -- - redis-cli -c get foo-0 + kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert -- + bash -c "cd /go/src/data-assert && go run main.go chk-redis-data --host redis-cluster-v1beta2-leader.${NAMESPACE}.svc.cluster.local:6379 --mode cluster" check: - (contains($stdout, 'bar-0')): true + (contains($stdout, 'OK')): true