Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
crawl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
crawl
Commits
c31b2d91
Commit
c31b2d91
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
add tests to scope.go
parent
4c82422d
No related branches found
Branches containing commit
No related tags found
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scope.go
+3
-0
3 additions, 0 deletions
scope.go
scope_test.go
+66
-0
66 additions, 0 deletions
scope_test.go
with
69 additions
and
0 deletions
scope.go
+
3
−
0
View file @
c31b2d91
...
...
@@ -57,6 +57,9 @@ func (m URLPrefixMap) Add(uri *url.URL) {
func
(
m
URLPrefixMap
)
Contains
(
uri
*
url
.
URL
)
bool
{
s
:=
strings
.
TrimPrefix
(
uri
.
Host
,
"www."
)
if
_
,
ok
:=
m
[
s
];
ok
{
return
true
}
for
_
,
p
:=
range
strings
.
Split
(
uri
.
Path
,
"/"
)
{
if
p
==
""
{
continue
...
...
This diff is collapsed.
Click to expand it.
scope_test.go
0 → 100644
+
66
−
0
View file @
c31b2d91
package
crawl
import
(
"net/url"
"testing"
)
func
mustParseURL
(
s
string
)
*
url
.
URL
{
u
,
_
:=
url
.
Parse
(
s
)
return
u
}
type
testScopeEntry
struct
{
uri
string
depth
int
expected
bool
}
func
runScopeTest
(
t
*
testing
.
T
,
sc
Scope
,
testdata
[]
testScopeEntry
)
{
for
_
,
td
:=
range
testdata
{
uri
:=
mustParseURL
(
td
.
uri
)
result
:=
sc
.
Check
(
uri
,
td
.
depth
)
if
result
!=
td
.
expected
{
t
.
Errorf
(
"Check(%s, %d) -> got %v, want %v"
,
td
.
uri
,
td
.
depth
,
result
,
td
.
expected
)
}
}
}
func
TestDepthScope
(
t
*
testing
.
T
)
{
td
:=
[]
testScopeEntry
{
{
"http://example.com"
,
1
,
true
},
{
"http://example.com"
,
10
,
false
},
{
"http://example.com"
,
100
,
false
},
}
runScopeTest
(
t
,
NewDepthScope
(
10
),
td
)
}
func
TestSchemeScope
(
t
*
testing
.
T
)
{
td
:=
[]
testScopeEntry
{
{
"http://example.com"
,
0
,
true
},
{
"https://example.com"
,
0
,
false
},
{
"ftp://example.com"
,
0
,
false
},
}
runScopeTest
(
t
,
NewSchemeScope
([]
string
{
"http"
}),
td
)
}
func
TestURLPrefixScope
(
t
*
testing
.
T
)
{
td
:=
[]
testScopeEntry
{
{
"http://example1.com"
,
0
,
true
},
{
"http://example1.com/"
,
0
,
true
},
{
"http://example1.com/some/path/"
,
0
,
true
},
{
"http://www.example1.com"
,
0
,
true
},
{
"http://subdomain.example1.com"
,
0
,
false
},
{
"http://example2.com"
,
0
,
false
},
{
"http://example2.com/"
,
0
,
false
},
{
"http://www.example2.com"
,
0
,
false
},
{
"http://example2.com/allowed/path/is/ok"
,
0
,
true
},
{
"http://example2.com/allowed/path"
,
0
,
true
},
{
"http://example2.com/another/path/is/not/ok"
,
0
,
false
},
}
pfx
:=
make
(
URLPrefixMap
)
pfx
.
Add
(
mustParseURL
(
"http://example1.com"
))
pfx
.
Add
(
mustParseURL
(
"http://example2.com/allowed/path/"
))
runScopeTest
(
t
,
NewURLPrefixScope
(
pfx
),
td
)
}
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