File: inode_parents_test.go

package info (click to toggle)
golang-github-hanwen-go-fuse 2.1.0%2Bgit20220822.58a7e14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,292 kB
  • sloc: cpp: 78; sh: 43; makefile: 16
file content (55 lines) | stat: -rw-r--r-- 1,177 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package fs

import (
	"testing"
)

func TestInodeParents(t *testing.T) {
	var p inodeParents
	var ino1, ino2, ino3 Inode

	// empty store should be empty without panicing
	if count := p.count(); count != 0 {
		t.Error(count)
	}
	if p.all() != nil {
		t.Error("empty store should return nil but did not")
	}

	// non-dupes should be stored
	all := []parentData{
		parentData{"foo", &ino1},
		parentData{"foo2", &ino1},
		parentData{"foo3", &ino1},
		parentData{"foo", &ino2},
		parentData{"foo", &ino3},
	}
	for i, v := range all {
		p.add(v)
		if count := p.count(); count != i+1 {
			t.Errorf("want=%d have=%d", i+1, count)
		}
		last := p.get()
		if *last != v {
			t.Error("get did not give us last-known parent")
		}
	}

	// adding dupes should not cause the count to increase, but
	// must cause get() to return the most recently added dupe.
	for _, v := range all {
		p.add(v)
		if count := p.count(); count != len(all) {
			t.Errorf("want=%d have=%d", len(all), count)
		}
		last := p.get()
		if *last != v {
			t.Error("get did not give us last-known parent")
		}
	}

	all2 := p.all()
	if len(all) != len(all2) {
		t.Errorf("want=%d have=%d", len(all), len(all2))
	}
}