@@ -114,17 +114,18 @@ func TestProductionServesTheMailStoreFromEncryptedStorage(t *testing.T) {
114114 if mapping (t , object (t , production , "StorageClass" , "email-encrypted-v2" )["parameters" ])["encrypted" ] != "true" {
115115 t .Fatal ("the V2 migration destination must encrypt at rest" )
116116 }
117- prepared := object (t , production , "PersistentVolumeClaim" , "email-data-encrypted-v2" )
118- metadata := mapping (t , prepared ["metadata" ])
119- spec := mapping (t , prepared ["spec" ])
117+ destination := object (t , production , "PersistentVolumeClaim" , "email-data-encrypted-v2" )
118+ metadata := mapping (t , destination ["metadata" ])
119+ spec := mapping (t , destination ["spec" ])
120+ labels , _ := metadata ["labels" ].(map [string ]any )
120121 if metadata ["namespace" ] != "private-mail" ||
121122 mapping (t , metadata ["annotations" ])["kustomize.toolkit.fluxcd.io/prune" ] != "disabled" ||
122- mapping ( t , metadata [ " labels" ]) ["platform.devantler.tech/storage-stage" ] != "prepared" ||
123+ labels ["platform.devantler.tech/storage-stage" ] != nil ||
123124 spec ["storageClassName" ] != "email-encrypted-v2" || spec ["volumeMode" ] != "Filesystem" ||
124125 ! reflect .DeepEqual (spec ["accessModes" ], []any {"ReadWriteOnce" }) ||
125126 mapping (t , mapping (t , spec ["resources" ])["requests" ])["storage" ] != "2Gi" ||
126127 spec ["volumeName" ] != nil || spec ["dataSource" ] != nil || spec ["dataSourceRef" ] != nil {
127- t .Fatal ("the V2 destination must be a distinct, retained, unbound 2 GiB filesystem claim" )
128+ t .Fatal ("the V2 destination must be a distinct, retained 2 GiB filesystem claim that waits for binding " )
128129 }
129130 pod := mapping (t , mapping (t , mapping (t , object (t , production , "StatefulSet" , "private-mail" )["spec" ])["template" ])["spec" ])
130131 volumes := map [string ]map [string ]any {}
@@ -135,8 +136,8 @@ func TestProductionServesTheMailStoreFromEncryptedStorage(t *testing.T) {
135136 }
136137 }
137138 if len (volumes ) != 2 || volumes ["data" ]["claimName" ] != "email-data-encrypted" || volumes ["data" ]["readOnly" ] == true ||
138- volumes ["legacy -data" ]["claimName" ] != "private-mail- data" || volumes ["legacy -data" ]["readOnly" ] ! = true {
139- t .Fatal ("the server must store data on the encrypted claim and see the original only read-only " )
139+ volumes ["v2 -data" ]["claimName" ] != "email- data-encrypted-v2 " || volumes ["v2 -data" ]["readOnly" ] = = true {
140+ t .Fatal ("both encrypted claims must be available to the rollback-safe selector " )
140141 }
141142 server := ""
142143 for _ , item := range sequence (t , pod ["containers" ]) {
@@ -145,30 +146,40 @@ func TestProductionServesTheMailStoreFromEncryptedStorage(t *testing.T) {
145146 server = stringField (t , container , "image" )
146147 }
147148 }
148- copySteps , sourceMounts := 0 , 0
149+ expected := map [ string ] bool { "select-mail-store" : true , "configure" : true , "private-mail" : true }
149150 for index , group := range []string {"initContainers" , "containers" } {
150151 for position , item := range sequence (t , pod [group ]) {
151152 container := mapping (t , item )
152153 name := stringField (t , container , "name" )
154+ if ! expected [name ] {
155+ continue
156+ }
157+ delete (expected , name )
158+ mounts := map [string ]map [string ]any {}
153159 for _ , mountItem := range sequence (t , container ["volumeMounts" ]) {
154160 mount := mapping (t , mountItem )
155- if mount ["name" ] != "legacy-data" {
156- continue
157- }
158- if index != 0 || position != 0 || name != "migrate-storage" || mount ["readOnly" ] != true {
159- t .Fatal ("only the first initializer, the copy step, may mount the original claim, and only read-only" )
161+ mounts [stringField (t , mount , "name" )] = mount
162+ if mount ["name" ] == "legacy-data" {
163+ t .Fatal ("the retired plaintext claim must not mount in the rollback artifact" )
160164 }
161- sourceMounts ++
162165 }
163- if name == "migrate-storage" {
164- copySteps ++
165- if index != 0 || position != 0 || container ["image" ] != server {
166- t .Fatal ("the copy must run first, before setup, with the server's signed image" )
167- }
166+ selecting := name == "select-mail-store"
167+ routeMount := "/etc/stalwart/config.json"
168+ if selecting {
169+ routeMount = "/store-selection"
170+ }
171+ if mounts ["serving-storage" ]["mountPath" ] != routeMount || (mounts ["serving-storage" ]["readOnly" ] == true ) == selecting ||
172+ ! selecting && mounts ["serving-storage" ]["subPath" ] != "config.json" ||
173+ mounts ["data" ]["mountPath" ] != "/var/lib/stalwart" || mounts ["v2-data" ]["mountPath" ] != "/var/lib/stalwart-v2" ||
174+ (mounts ["v2-data" ]["readOnly" ] == true ) != selecting {
175+ t .Fatalf ("%s does not use the shared fenced storage route" , name )
176+ }
177+ if selecting && (index != 0 || position != 0 || container ["image" ] != server ) {
178+ t .Fatal ("the selector must run before setup with the server's signed image" )
168179 }
169180 }
170181 }
171- if copySteps != 1 || sourceMounts != 1 {
172- t .Fatal ( "exactly one copy step must mount the original claim exactly once" )
182+ if len ( expected ) != 0 {
183+ t .Fatalf ( "missing storage consumers: %v" , expected )
173184 }
174185}
0 commit comments