@@ -233,6 +233,97 @@ func TestReadSnapshotFile(t *testing.T) {
233233 expected := fmt .Errorf ("unable to parse Snapshot specification from %s: %w" , spec , wrapped )
234234 assert .Error (t , err , expected )
235235 })
236+
237+ t .Run ("Snapshot with .spec wrapper (cluster record format)" , func (t * testing.T ) {
238+ snapshotSpec := app.SnapshotSpec {
239+ Components : []app.SnapshotComponent {
240+ {
241+ Name : "Named" ,
242+ ContainerImage : "registry.io/repository/image:tag" ,
243+ },
244+ },
245+ }
246+ fs := afero .NewMemMapFs ()
247+ // Simulate a cluster record format with .spec wrapper
248+ clusterRecord := `{
249+ "apiVersion": "appstudio.redhat.com/v1alpha1",
250+ "kind": "Snapshot",
251+ "metadata": {
252+ "name": "vsa-demo-app-x9xln",
253+ "namespace": "user-ns2"
254+ },
255+ "spec": {
256+ "components": [
257+ {
258+ "name": "Named",
259+ "containerImage": "registry.io/repository/image:tag"
260+ }
261+ ]
262+ }
263+ }`
264+
265+ err := afero .WriteFile (fs , "/cluster-record.json" , []byte (clusterRecord ), 0644 )
266+ if err != nil {
267+ t .Fatalf ("Setup failure: could not write file: %v" , err )
268+ }
269+
270+ content , err := afero .ReadFile (fs , "/cluster-record.json" )
271+ assert .NoError (t , err )
272+ got , err := readSnapshotSource (content )
273+ assert .NoError (t , err )
274+ assert .Equal (t , snapshotSpec , got )
275+ })
276+
277+ t .Run ("Snapshot with .spec wrapper in YAML format" , func (t * testing.T ) {
278+ snapshotSpec := app.SnapshotSpec {
279+ Components : []app.SnapshotComponent {
280+ {
281+ Name : "Named" ,
282+ ContainerImage : "registry.io/repository/image:tag" ,
283+ },
284+ },
285+ }
286+ // Simulate a cluster record format with .spec wrapper in YAML
287+ clusterRecord := `apiVersion: appstudio.redhat.com/v1alpha1
288+ kind: Snapshot
289+ metadata:
290+ name: vsa-demo-app-x9xln
291+ namespace: user-ns2
292+ spec:
293+ components:
294+ - name: Named
295+ containerImage: registry.io/repository/image:tag`
296+
297+ content := []byte (clusterRecord )
298+ got , err := readSnapshotSource (content )
299+ assert .NoError (t , err )
300+ assert .Equal (t , snapshotSpec , got )
301+ })
302+
303+ t .Run ("Snapshot without .spec wrapper (backward compatibility)" , func (t * testing.T ) {
304+ snapshotSpec := app.SnapshotSpec {
305+ Components : []app.SnapshotComponent {
306+ {
307+ Name : "Named" ,
308+ ContainerImage : "registry.io/repository/image:tag" ,
309+ },
310+ },
311+ }
312+ // Direct SnapshotSpec without wrapper (existing behavior)
313+ directSpec := `{
314+ "components": [
315+ {
316+ "name": "Named",
317+ "containerImage": "registry.io/repository/image:tag"
318+ }
319+ ]
320+ }`
321+
322+ content := []byte (directSpec )
323+ got , err := readSnapshotSource (content )
324+ assert .NoError (t , err )
325+ assert .Equal (t , snapshotSpec , got )
326+ })
236327}
237328
238329func TestExpandImageIndex (t * testing.T ) {
0 commit comments