4 "git.curoverse.com/arvados.git/sdk/go/blockdigest"
10 func getStackTrace() (string) {
11 buf := make([]byte, 1000)
12 bytes_written := runtime.Stack(buf, false)
13 return "Stack Trace:\n" + string(buf[:bytes_written])
16 func expectFromChannel(t *testing.T, c <-chan string, expected string) {
19 t.Fatalf("Expected to receive %s but channel was closed. %s",
23 if actual != expected {
24 t.Fatalf("Expected %s but got %s instead. %s",
31 func expectChannelClosed(t *testing.T, c <-chan interface{}) {
34 t.Fatalf("Expected channel to be closed, but received %v instead. %s",
40 func expectEqual(t *testing.T, actual interface{}, expected interface{}) {
41 if actual != expected {
42 t.Fatalf("Expected %v but received %v instead. %s",
49 func expectStringSlicesEqual(t *testing.T, actual []string, expected []string) {
50 if len(actual) != len(expected) {
51 t.Fatalf("Expected %v (length %d), but received %v (length %d) instead. %s", expected, len(expected), actual, len(actual), getStackTrace())
53 for i := range actual {
54 if actual[i] != expected[i] {
55 t.Fatalf("Expected %v but received %v instead (first disagreement at position %d). %s", expected, actual, i, getStackTrace())
60 func expectManifestStream(t *testing.T, actual ManifestStream, expected ManifestStream) {
61 expectEqual(t, actual.StreamName, expected.StreamName)
62 expectStringSlicesEqual(t, actual.Blocks, expected.Blocks)
63 expectStringSlicesEqual(t, actual.Files, expected.Files)
66 func expectBlockLocator(t *testing.T, actual BlockLocator, expected BlockLocator) {
67 expectEqual(t, actual.Digest, expected.Digest)
68 expectEqual(t, actual.Size, expected.Size)
69 expectStringSlicesEqual(t, actual.Hints, expected.Hints)
72 func expectLocatorPatternMatch(t *testing.T, s string) {
73 if !LocatorPattern.MatchString(s) {
74 t.Fatalf("Expected \"%s\" to match locator pattern but it did not.",
79 func expectLocatorPatternFail(t *testing.T, s string) {
80 if LocatorPattern.MatchString(s) {
81 t.Fatalf("Expected \"%s\" to fail locator pattern but it passed.",
86 func TestLocatorPatternBasic(t *testing.T) {
87 expectLocatorPatternMatch(t, "12345678901234567890123456789012+12345")
88 expectLocatorPatternMatch(t, "A2345678901234abcdefababdeffdfdf+12345")
89 expectLocatorPatternMatch(t, "12345678901234567890123456789012+12345+A1")
90 expectLocatorPatternMatch(t,
91 "12345678901234567890123456789012+12345+A1+B123wxyz@_-")
92 expectLocatorPatternMatch(t,
93 "12345678901234567890123456789012+12345+A1+B123wxyz@_-+C@")
95 expectLocatorPatternFail(t, "12345678901234567890123456789012")
96 expectLocatorPatternFail(t, "12345678901234567890123456789012+")
97 expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+")
98 expectLocatorPatternFail(t, "1234567890123456789012345678901+12345")
99 expectLocatorPatternFail(t, "123456789012345678901234567890123+12345")
100 expectLocatorPatternFail(t, "g2345678901234abcdefababdeffdfdf+12345")
101 expectLocatorPatternFail(t, "12345678901234567890123456789012+12345 ")
102 expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+1")
103 expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+1A")
104 expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A")
105 expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+a1")
106 expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A1+")
107 expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A1+B")
108 expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A+B2")
111 func TestParseManifestStreamSimple(t *testing.T) {
112 m := parseManifestStream(". 365f83f5f808896ec834c8b595288735+2310+K@qr1hi+Af0c9a66381f3b028677411926f0be1c6282fe67c@542b5ddf 0:2310:qr1hi-8i9sb-ienvmpve1a0vpoi.log.txt")
113 expectManifestStream(t, m, ManifestStream{StreamName: ".",
114 Blocks: []string{"365f83f5f808896ec834c8b595288735+2310+K@qr1hi+Af0c9a66381f3b028677411926f0be1c6282fe67c@542b5ddf"},
115 Files: []string{"0:2310:qr1hi-8i9sb-ienvmpve1a0vpoi.log.txt"}})
118 func TestParseBlockLocatorSimple(t *testing.T) {
119 b, err := ParseBlockLocator("365f83f5f808896ec834c8b595288735+2310+K@qr1hi+Af0c9a66381f3b028677411926f0be1c6282fe67c@542b5ddf")
121 t.Fatalf("Unexpected error parsing block locator: %v", err)
123 expectBlockLocator(t, b, BlockLocator{Digest: blockdigest.AssertFromString("365f83f5f808896ec834c8b595288735"),
125 Hints: []string{"K@qr1hi",
126 "Af0c9a66381f3b028677411926f0be1c6282fe67c@542b5ddf"}})
129 func TestStreamIterShortManifestWithBlankStreams(t *testing.T) {
130 content, err := ioutil.ReadFile("testdata/short_manifest")
132 t.Fatalf("Unexpected error reading manifest from file: %v", err)
134 manifest := Manifest{string(content)}
135 streamIter := manifest.StreamIter()
137 firstStream := <-streamIter
138 expectManifestStream(t,
140 ManifestStream{StreamName: ".",
141 Blocks: []string{"b746e3d2104645f2f64cd3cc69dd895d+15693477+E2866e643690156651c03d876e638e674dcd79475@5441920c"},
142 Files: []string{"0:15893477:chr10_band0_s0_e3000000.fj"}})
144 received, ok := <- streamIter
146 t.Fatalf("Expected streamIter to be closed, but received %v instead.",
151 func TestBlockIterLongManifest(t *testing.T) {
152 content, err := ioutil.ReadFile("testdata/long_manifest")
154 t.Fatalf("Unexpected error reading manifest from file: %v", err)
156 manifest := Manifest{string(content)}
157 blockChannel := manifest.BlockIterWithDuplicates()
159 firstBlock := <-blockChannel
160 expectBlockLocator(t,
162 BlockLocator{Digest: blockdigest.AssertFromString("b746e3d2104645f2f64cd3cc69dd895d"),
164 Hints: []string{"E2866e643690156651c03d876e638e674dcd79475@5441920c"}})
166 var lastBlock BlockLocator
167 for lastBlock = range blockChannel {
168 //log.Printf("Blocks Read: %d", blocksRead)
171 expectEqual(t, blocksRead, 853)
173 expectBlockLocator(t,
175 BlockLocator{Digest: blockdigest.AssertFromString("f9ce82f59e5908d2d70e18df9679b469"),
177 Hints: []string{"E53f903684239bcc114f7bf8ff9bd6089f33058db@5441920c"}})