TestPoolDevice runs integration tests for pool device. The following scenario implemented: - Create pool device with name 'test-pool-device' - Create two thin volumes 'thin-1' and 'thin-2' - Write ext4 file system on 'thin-1' and make sure it'errs moutable - Write v1 test file on 'thin-1' volume - T
(t *testing.T)
| 55 | // - Mount 'snap-1' and make sure test file is v1 |
| 56 | // - Unmount volumes and remove all devices |
| 57 | func TestPoolDevice(t *testing.T) { |
| 58 | testutil.RequiresRoot(t) |
| 59 | |
| 60 | assert.NoError(t, log.SetLevel("debug")) |
| 61 | ctx := context.Background() |
| 62 | |
| 63 | tempDir := t.TempDir() |
| 64 | |
| 65 | _, loopDataDevice := createLoopbackDevice(t, tempDir) |
| 66 | _, loopMetaDevice := createLoopbackDevice(t, tempDir) |
| 67 | |
| 68 | poolName := fmt.Sprintf("test-pool-device-%d", time.Now().Nanosecond()) |
| 69 | err := dmsetup.CreatePool(poolName, loopDataDevice, loopMetaDevice, 64*1024/dmsetup.SectorSize) |
| 70 | assert.Nil(t, err, "failed to create pool %q", poolName) |
| 71 | |
| 72 | defer func() { |
| 73 | // Detach loop devices and remove images |
| 74 | err := mount.DetachLoopDevice(loopDataDevice, loopMetaDevice) |
| 75 | assert.NoError(t, err) |
| 76 | }() |
| 77 | |
| 78 | config := &Config{ |
| 79 | PoolName: poolName, |
| 80 | RootPath: tempDir, |
| 81 | BaseImageSize: "16mb", |
| 82 | BaseImageSizeBytes: 16 * 1024 * 1024, |
| 83 | DiscardBlocks: true, |
| 84 | } |
| 85 | |
| 86 | pool, err := NewPoolDevice(ctx, config) |
| 87 | assert.Nil(t, err, "can't create device pool") |
| 88 | assert.True(t, pool != nil) |
| 89 | |
| 90 | defer func() { |
| 91 | err := pool.RemovePool(ctx) |
| 92 | assert.Nil(t, err, "can't close device pool") |
| 93 | }() |
| 94 | |
| 95 | // Create thin devices |
| 96 | t.Run("CreateThinDevice", func(t *testing.T) { |
| 97 | testCreateThinDevice(t, pool) |
| 98 | }) |
| 99 | |
| 100 | // Make ext4 filesystem on 'thin-1' |
| 101 | t.Run("MakeFileSystem", func(t *testing.T) { |
| 102 | testMakeFileSystem(t, pool) |
| 103 | }) |
| 104 | |
| 105 | // Mount 'thin-1' and write v1 test file on 'thin-1' device |
| 106 | err = mount.WithTempMount(ctx, getMounts(thinDevice1), func(thin1MountPath string) error { |
| 107 | // Write v1 test file on 'thin-1' device |
| 108 | thin1TestFilePath := filepath.Join(thin1MountPath, "TEST") |
| 109 | err := os.WriteFile(thin1TestFilePath, []byte("test file (v1)"), 0700) |
| 110 | assert.Nil(t, err, "failed to write test file v1 on '%s' volume", thinDevice1) |
| 111 | |
| 112 | return nil |
| 113 | }) |
| 114 |
nothing calls this directly
no test coverage detected
searching dependent graphs…