(t *testing.T)
| 37 | ) |
| 38 | |
| 39 | func TestLoopbackMount(t *testing.T) { |
| 40 | testutil.RequiresRoot(t) |
| 41 | ctx := logtest.WithT(context.Background(), t) |
| 42 | ctx = namespaces.WithNamespace(ctx, "test") |
| 43 | td := t.TempDir() |
| 44 | metadb := filepath.Join(td, "mounts.db") |
| 45 | targetdir := filepath.Join(td, "m") |
| 46 | db, err := bolt.Open(metadb, 0600, nil) |
| 47 | if err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | |
| 51 | a := fstest.Apply( |
| 52 | fstest.CreateFile("/foo", []byte("foo\n"), 0777), |
| 53 | fstest.CreateDir("/a", 0755), |
| 54 | fstest.CreateDir("/a/b", 0755), |
| 55 | fstest.CreateDir("/a/b/c", 0755), |
| 56 | ) |
| 57 | |
| 58 | source, err := initalizeBlockDevice(td, a) |
| 59 | if err != nil { |
| 60 | t.Fatal(err) |
| 61 | } |
| 62 | mounts := []mount.Mount{ |
| 63 | { |
| 64 | Type: "loop", |
| 65 | Source: source, |
| 66 | Options: []string{}, |
| 67 | }, |
| 68 | { |
| 69 | Type: "format/ext4", |
| 70 | Source: "{{ mount 0 }}", // previous mount |
| 71 | Options: []string{}, |
| 72 | }, |
| 73 | } |
| 74 | |
| 75 | m, err := NewManager(db, targetdir, WithMountHandler("loop", mount.LoopbackHandler())) |
| 76 | require.NoError(t, err) |
| 77 | ainfo, err := m.Activate(ctx, "id1", mounts) |
| 78 | require.NoError(t, err) |
| 79 | defer func() { |
| 80 | assert.NoError(t, m.Deactivate(ctx, "id1")) |
| 81 | }() |
| 82 | |
| 83 | tm, err := os.MkdirTemp(td, "test-mount-") |
| 84 | if err != nil { |
| 85 | t.Fatal(err) |
| 86 | } |
| 87 | |
| 88 | actual, err := os.MkdirTemp(td, "actual-") |
| 89 | if err != nil { |
| 90 | t.Fatal(err) |
| 91 | } |
| 92 | |
| 93 | if err := a.Apply(actual); err != nil { |
| 94 | t.Fatal(err) |
| 95 | } |
| 96 |
nothing calls this directly
no test coverage detected
searching dependent graphs…