-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpathelement_test.go
54 lines (43 loc) · 1.66 KB
/
pathelement_test.go
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
package whatnot
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPathElements(t *testing.T) {
t.Run("Append Element to Existing Element", appendPathElement)
gns := createTestNamespace(t)
testPathString := PathString("/path/to/test/data")
testpath := testPathString.ToAbsolutePath()
err := gns.RegisterAbsolutePath(testpath)
if !assert.Nil(t, err, "registerabsolute path returned error") {
t.Error(err.Error())
return
}
lastElement := gns.FetchAbsolutePath(testPathString)
if !assert.NotNil(t, lastElement, "did not return last element in absolute path") {
t.Error("did not find registered path element")
return
}
if !assert.Equal(t, lastElement.AbsolutePath(), testpath, "returned element absolutepath did not match original") {
t.Error("mismatched return path")
return
}
extraElement, err := lastElement.AppendRelativePath(PathString("subdata"))
if !assert.Nil(t, err, "appending another sub-element returned error") {
t.Error(err.Error())
return
}
if !assert.Equal(t, SubPath("subdata"), extraElement.SubPath(), "did not match original subpath string") {
t.Error("mismatch between provided and created subpath")
}
if !assert.Equal(t, lastElement, extraElement.Parent(), "incorrect parent returned") {
t.Error("new element did not obtain correct parent element")
return
}
if !assert.Equal(t, extraElement, lastElement.fetchSubElement(SubPath("subdata")), "sub-element not reachable from parent element") {
t.Error("parent element of created sub-element not linked to new sub element correctly")
}
}
func appendPathElement(t *testing.T) {
t.Log("Testing that appending a path element to an existing path element succeeds")
}