package scripts_test import ( "os" "path/filepath" "testing" "gopkg.in/yaml.v3" ) // The quick start's own-PVC example mounts on an install with several nodes: // its PVC uses the StorageClass the chart installs, which carries the CHAP // node-stage Secret whenever CHAP is on (chap.enabled with // storageClass.nodeStageSecret.enabled, the default), and the example writer // and reader pods claim that PVC. func TestOwnPVCExampleUsesTheChartsStorageClass(t *testing.T) { root := repoRoot(t) read := func(p ...string) map[string]any { t.Helper() b, err := os.ReadFile(filepath.Join(append([]string{root}, p...)...)) if err != nil { t.Fatal(err) } doc := map[string]any{} if err := yaml.Unmarshal(b, &doc); err != nil { t.Fatal(err) } return doc } pvc := read("examples", "kubernetes", "basic-app", "pvc.yaml") values := read("charts", "seaweed-block", "values.yaml") sc := values["storageClass"].(map[string]any) if got := pvc["spec"].(map[string]any)["storageClassName"]; got != sc["name"] { t.Fatalf("pvc.yaml storageClassName %v, want the chart's StorageClass %v", got, sc["name"]) } if sc["nodeStageSecret"].(map[string]any)["enabled"] != true { t.Fatal("the chart's StorageClass does not carry the node-stage Secret by default") } name := pvc["metadata"].(map[string]any)["name"] for _, pod := range []string{"writer-pod.yaml", "reader-pod.yaml"} { spec := read("examples", "kubernetes", "basic-app", pod)["spec"].(map[string]any) claim := spec["volumes"].([]any)[0].(map[string]any)["persistentVolumeClaim"].(map[string]any)["claimName"] if claim != name { t.Errorf("%s claims %v, want the example PVC %v", pod, claim, name) } } }