(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestGetInstanceSnapshots(t *testing.T) { |
| 19 | tx, cleanup := db.NewTestClusterTx(t) |
| 20 | defer cleanup() |
| 21 | |
| 22 | nodeID1 := int64(1) // This is the default local member |
| 23 | |
| 24 | addContainer(t, tx, nodeID1, "c1") |
| 25 | addContainer(t, tx, nodeID1, "c2") |
| 26 | |
| 27 | addInstanceSnapshot(t, tx, 1, "snap1") |
| 28 | addInstanceSnapshot(t, tx, 2, "snap2") |
| 29 | addInstanceSnapshot(t, tx, 2, "snap3") |
| 30 | |
| 31 | addInstanceSnapshotConfig(t, tx, "c2", "snap2", "x", "y") |
| 32 | |
| 33 | addInstanceSnapshotDevice(t, tx, "c2", "snap2", "eth0", "nic", nil) |
| 34 | addInstanceSnapshotDevice(t, tx, "c2", "snap3", "root", "disk", map[string]string{"x": "y"}) |
| 35 | |
| 36 | snapshots, err := cluster.GetInstanceSnapshots(context.TODO(), tx.Tx()) |
| 37 | require.NoError(t, err) |
| 38 | assert.Len(t, snapshots, 3) |
| 39 | |
| 40 | s1Config, err := cluster.GetInstanceSnapshotConfig(context.TODO(), tx.Tx(), snapshots[0].ID) |
| 41 | require.NoError(t, err) |
| 42 | s1Devices, err := cluster.GetInstanceSnapshotDevices(context.TODO(), tx.Tx(), snapshots[0].ID) |
| 43 | require.NoError(t, err) |
| 44 | |
| 45 | s1 := snapshots[0] |
| 46 | assert.Equal(t, "snap1", s1.Name) |
| 47 | assert.Equal(t, "c1", s1.Instance) |
| 48 | assert.Equal(t, map[string]string{}, s1Config) |
| 49 | assert.Len(t, s1Devices, 0) |
| 50 | |
| 51 | s2Config, err := cluster.GetInstanceSnapshotConfig(context.TODO(), tx.Tx(), snapshots[1].ID) |
| 52 | require.NoError(t, err) |
| 53 | s2Devices, err := cluster.GetInstanceSnapshotDevices(context.TODO(), tx.Tx(), snapshots[1].ID) |
| 54 | require.NoError(t, err) |
| 55 | |
| 56 | s2 := snapshots[1] |
| 57 | assert.Equal(t, "snap2", s2.Name) |
| 58 | assert.Equal(t, "c2", s2.Instance) |
| 59 | assert.Equal(t, map[string]string{"x": "y"}, s2Config) |
| 60 | assert.Len(t, s2Devices, 1) |
| 61 | assert.Equal(t, "eth0", s2Devices["eth0"].Name) |
| 62 | assert.Equal(t, "nic", s2Devices["eth0"].Type.String()) |
| 63 | assert.Equal(t, map[string]string{}, s2Devices["eth0"].Config) |
| 64 | |
| 65 | s3Config, err := cluster.GetInstanceSnapshotConfig(context.TODO(), tx.Tx(), snapshots[2].ID) |
| 66 | require.NoError(t, err) |
| 67 | s3Devices, err := cluster.GetInstanceSnapshotDevices(context.TODO(), tx.Tx(), snapshots[2].ID) |
| 68 | require.NoError(t, err) |
| 69 | |
| 70 | s3 := snapshots[2] |
| 71 | assert.Equal(t, "snap3", s3.Name) |
| 72 | assert.Equal(t, "c2", s3.Instance) |
| 73 | assert.Equal(t, map[string]string{}, s3Config) |
| 74 | assert.Len(t, s3Devices, 1) |
| 75 | assert.Equal(t, "root", s3Devices["root"].Name) |
nothing calls this directly
no test coverage detected
searching dependent graphs…