good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
03ec3fed
Commit
03ec3fed
authored
Oct 18, 2017
by
Fabio Barone
Browse files
Options
Downloads
Patches
Plain Diff
swarm/api: bug fix exact match for manifest
parent
3d88ecd6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
swarm/api/manifest.go
+10
-0
10 additions, 0 deletions
swarm/api/manifest.go
swarm/api/manifest_test.go
+51
-27
51 additions, 27 deletions
swarm/api/manifest_test.go
with
61 additions
and
27 deletions
swarm/api/manifest.go
+
10
−
0
View file @
03ec3fed
...
@@ -436,6 +436,16 @@ func (self *manifestTrie) findPrefixOf(path string, quitC chan bool) (entry *man
...
@@ -436,6 +436,16 @@ func (self *manifestTrie) findPrefixOf(path string, quitC chan bool) (entry *man
if
len
(
path
)
<=
epl
{
if
len
(
path
)
<=
epl
{
if
entry
.
Path
[
:
len
(
path
)]
==
path
{
if
entry
.
Path
[
:
len
(
path
)]
==
path
{
if
entry
.
ContentType
==
ManifestType
{
if
entry
.
ContentType
==
ManifestType
{
err
:=
self
.
loadSubTrie
(
entry
,
quitC
)
if
err
==
nil
&&
entry
.
subtrie
!=
nil
{
subentries
:=
entry
.
subtrie
.
entries
for
i
:=
0
;
i
<
len
(
subentries
);
i
++
{
sub
:=
subentries
[
i
]
if
sub
!=
nil
&&
sub
.
Path
==
""
{
return
sub
,
len
(
path
)
}
}
}
entry
.
Status
=
http
.
StatusMultipleChoices
entry
.
Status
=
http
.
StatusMultipleChoices
}
}
pos
=
len
(
path
)
pos
=
len
(
path
)
...
...
This diff is collapsed.
Click to expand it.
swarm/api/manifest_test.go
+
51
−
27
View file @
03ec3fed
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io"
"io"
"net/http"
"strings"
"strings"
"testing"
"testing"
...
@@ -39,17 +40,17 @@ func manifest(paths ...string) (manifestReader storage.LazySectionReader) {
...
@@ -39,17 +40,17 @@ func manifest(paths ...string) (manifestReader storage.LazySectionReader) {
}
}
}
}
func
testGetEntry
(
t
*
testing
.
T
,
path
,
match
string
,
paths
...
string
)
*
manifestTrie
{
func
testGetEntry
(
t
*
testing
.
T
,
path
,
match
string
,
multiple
bool
,
paths
...
string
)
*
manifestTrie
{
quitC
:=
make
(
chan
bool
)
quitC
:=
make
(
chan
bool
)
trie
,
err
:=
readManifest
(
manifest
(
paths
...
),
nil
,
nil
,
quitC
)
trie
,
err
:=
readManifest
(
manifest
(
paths
...
),
nil
,
nil
,
quitC
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error making manifest: %v"
,
err
)
t
.
Errorf
(
"unexpected error making manifest: %v"
,
err
)
}
}
checkEntry
(
t
,
path
,
match
,
trie
)
checkEntry
(
t
,
path
,
match
,
multiple
,
trie
)
return
trie
return
trie
}
}
func
checkEntry
(
t
*
testing
.
T
,
path
,
match
string
,
trie
*
manifestTrie
)
{
func
checkEntry
(
t
*
testing
.
T
,
path
,
match
string
,
multiple
bool
,
trie
*
manifestTrie
)
{
entry
,
fullpath
:=
trie
.
getEntry
(
path
)
entry
,
fullpath
:=
trie
.
getEntry
(
path
)
if
match
==
"-"
&&
entry
!=
nil
{
if
match
==
"-"
&&
entry
!=
nil
{
t
.
Errorf
(
"expected no match for '%s', got '%s'"
,
path
,
fullpath
)
t
.
Errorf
(
"expected no match for '%s', got '%s'"
,
path
,
fullpath
)
...
@@ -60,32 +61,55 @@ func checkEntry(t *testing.T, path, match string, trie *manifestTrie) {
...
@@ -60,32 +61,55 @@ func checkEntry(t *testing.T, path, match string, trie *manifestTrie) {
}
else
if
fullpath
!=
match
{
}
else
if
fullpath
!=
match
{
t
.
Errorf
(
"incorrect entry retrieved for '%s'. expected path '%v', got '%s'"
,
path
,
match
,
fullpath
)
t
.
Errorf
(
"incorrect entry retrieved for '%s'. expected path '%v', got '%s'"
,
path
,
match
,
fullpath
)
}
}
if
multiple
&&
entry
.
Status
!=
http
.
StatusMultipleChoices
{
t
.
Errorf
(
"Expected %d Multiple Choices Status for path %s, match %s, got %d"
,
http
.
StatusMultipleChoices
,
path
,
match
,
entry
.
Status
)
}
else
if
!
multiple
&&
entry
!=
nil
&&
entry
.
Status
==
http
.
StatusMultipleChoices
{
t
.
Errorf
(
"Were not expecting %d Multiple Choices Status for path %s, match %s, but got it"
,
http
.
StatusMultipleChoices
,
path
,
match
)
}
}
}
func
TestGetEntry
(
t
*
testing
.
T
)
{
func
TestGetEntry
(
t
*
testing
.
T
)
{
// file system manifest always contains regularized paths
// file system manifest always contains regularized paths
testGetEntry
(
t
,
"a"
,
"a"
,
"a"
)
testGetEntry
(
t
,
"a"
,
"a"
,
false
,
"a"
)
testGetEntry
(
t
,
"b"
,
"-"
,
"a"
)
testGetEntry
(
t
,
"b"
,
"-"
,
false
,
"a"
)
testGetEntry
(
t
,
"/a//"
,
"a"
,
"a"
)
testGetEntry
(
t
,
"/a//"
,
"a"
,
false
,
"a"
)
// fallback
// fallback
testGetEntry
(
t
,
"/a"
,
""
,
""
)
testGetEntry
(
t
,
"/a"
,
""
,
false
,
""
)
testGetEntry
(
t
,
"/a/b"
,
"a/b"
,
"a/b"
)
testGetEntry
(
t
,
"/a/b"
,
"a/b"
,
false
,
"a/b"
)
// longest/deepest math
// longest/deepest math
testGetEntry
(
t
,
"read"
,
"read"
,
"readme.md"
,
"readit.md"
)
testGetEntry
(
t
,
"read"
,
"read"
,
true
,
"readme.md"
,
"readit.md"
)
testGetEntry
(
t
,
"rf"
,
"-"
,
"readme.md"
,
"readit.md"
)
testGetEntry
(
t
,
"rf"
,
"-"
,
false
,
"readme.md"
,
"readit.md"
)
testGetEntry
(
t
,
"readme"
,
"readme"
,
"readme.md"
)
testGetEntry
(
t
,
"readme"
,
"readme"
,
false
,
"readme.md"
)
testGetEntry
(
t
,
"readme"
,
"-"
,
"readit.md"
)
testGetEntry
(
t
,
"readme"
,
"-"
,
false
,
"readit.md"
)
testGetEntry
(
t
,
"readme.md"
,
"readme.md"
,
"readme.md"
)
testGetEntry
(
t
,
"readme.md"
,
"readme.md"
,
false
,
"readme.md"
)
testGetEntry
(
t
,
"readme.md"
,
"-"
,
"readit.md"
)
testGetEntry
(
t
,
"readme.md"
,
"-"
,
false
,
"readit.md"
)
testGetEntry
(
t
,
"readmeAmd"
,
"-"
,
"readit.md"
)
testGetEntry
(
t
,
"readmeAmd"
,
"-"
,
false
,
"readit.md"
)
testGetEntry
(
t
,
"readme.mdffff"
,
"-"
,
"readme.md"
)
testGetEntry
(
t
,
"readme.mdffff"
,
"-"
,
false
,
"readme.md"
)
testGetEntry
(
t
,
"ab"
,
"ab"
,
"ab/cefg"
,
"ab/cedh"
,
"ab/kkkkkk"
)
testGetEntry
(
t
,
"ab"
,
"ab"
,
true
,
"ab/cefg"
,
"ab/cedh"
,
"ab/kkkkkk"
)
testGetEntry
(
t
,
"ab/ce"
,
"ab/ce"
,
"ab/cefg"
,
"ab/cedh"
,
"ab/ceuuuuuuuuuu"
)
testGetEntry
(
t
,
"ab/ce"
,
"ab/ce"
,
true
,
"ab/cefg"
,
"ab/cedh"
,
"ab/ceuuuuuuuuuu"
)
testGetEntry
(
t
,
"abc"
,
"abc"
,
"abcd"
,
"abczzzzef"
,
"abc/def"
,
"abc/e/g"
)
testGetEntry
(
t
,
"abc"
,
"abc"
,
true
,
"abcd"
,
"abczzzzef"
,
"abc/def"
,
"abc/e/g"
)
testGetEntry
(
t
,
"a/b"
,
"a/b"
,
"a"
,
"a/bc"
,
"a/ba"
,
"a/b/c"
)
testGetEntry
(
t
,
"a/b"
,
"a/b"
,
true
,
"a"
,
"a/bc"
,
"a/ba"
,
"a/b/c"
)
testGetEntry
(
t
,
"a/b"
,
"a/b"
,
"a"
,
"a/b"
,
"a/bb"
,
"a/b/c"
)
testGetEntry
(
t
,
"a/b"
,
"a/b"
,
false
,
"a"
,
"a/b"
,
"a/bb"
,
"a/b/c"
)
testGetEntry
(
t
,
"//a//b//"
,
"a/b"
,
"a"
,
"a/b"
,
"a/bb"
,
"a/b/c"
)
testGetEntry
(
t
,
"//a//b//"
,
"a/b"
,
false
,
"a"
,
"a/b"
,
"a/bb"
,
"a/b/c"
)
}
}
func
TestExactMatch
(
t
*
testing
.
T
)
{
quitC
:=
make
(
chan
bool
)
mf
:=
manifest
(
"shouldBeExactMatch.css"
,
"shouldBeExactMatch.css.map"
)
trie
,
err
:=
readManifest
(
mf
,
nil
,
nil
,
quitC
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error making manifest: %v"
,
err
)
}
entry
,
_
:=
trie
.
getEntry
(
"shouldBeExactMatch.css"
)
if
entry
.
Path
!=
""
{
t
.
Errorf
(
"Expected entry to match %s, got: %s"
,
"shouldBeExactMatch.css"
,
entry
.
Path
)
}
if
entry
.
Status
==
http
.
StatusMultipleChoices
{
t
.
Errorf
(
"Got status %d, which is unexepcted"
,
http
.
StatusMultipleChoices
)
}
}
func
TestDeleteEntry
(
t
*
testing
.
T
)
{
func
TestDeleteEntry
(
t
*
testing
.
T
)
{
}
}
...
@@ -108,15 +132,15 @@ func TestAddFileWithManifestPath(t *testing.T) {
...
@@ -108,15 +132,15 @@ func TestAddFileWithManifestPath(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
checkEntry
(
t
,
"ab"
,
"ab"
,
trie
)
checkEntry
(
t
,
"ab"
,
"ab"
,
false
,
trie
)
checkEntry
(
t
,
"ac"
,
"ac"
,
trie
)
checkEntry
(
t
,
"ac"
,
"ac"
,
false
,
trie
)
// now add path "a" and check we can still get "ab" and "ac"
// now add path "a" and check we can still get "ab" and "ac"
entry
:=
&
manifestTrieEntry
{}
entry
:=
&
manifestTrieEntry
{}
entry
.
Path
=
"a"
entry
.
Path
=
"a"
entry
.
Hash
=
"a"
entry
.
Hash
=
"a"
trie
.
addEntry
(
entry
,
nil
)
trie
.
addEntry
(
entry
,
nil
)
checkEntry
(
t
,
"ab"
,
"ab"
,
trie
)
checkEntry
(
t
,
"ab"
,
"ab"
,
false
,
trie
)
checkEntry
(
t
,
"ac"
,
"ac"
,
trie
)
checkEntry
(
t
,
"ac"
,
"ac"
,
false
,
trie
)
checkEntry
(
t
,
"a"
,
"a"
,
trie
)
checkEntry
(
t
,
"a"
,
"a"
,
false
,
trie
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment