forked from opensciencegrid/stashcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamespaces_test.go
47 lines (38 loc) · 1.34 KB
/
namespaces_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
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
// TestMatchNamespace calls MatchNamespace with a hostname, checking
// for a valid return value.
func TestMatchNamespace(t *testing.T) {
namespacesYaml = []byte(`
- path: /ospool/PROTECTED
readhttps: true
usetokenonread: true
writebackhost: https://origin-auth2001.chtc.wisc.edu:1095
dirlisthost: https://origin-auth2001.chtc.wisc.edu:1095
- path: /osgconnect/private
readhttps: true
usetokenonread: true
writebackhost: https://stash-xrd.osgconnect.net:1094
- path: /osgconnect
writebackhost: https://stash-xrd.osgconnect.net:1094
dirlisthost: http://stash.osgconnect.net:1094
`)
ns, err := MatchNamespace("/osgconnect/private/path/to/file.txt")
assert.NoError(t, err, "Failed to parse namespace")
assert.Equal(t, "/osgconnect/private", ns.Path)
assert.Equal(t, true, ns.ReadHTTPS)
// Check for empty
ns, err = MatchNamespace("/does/not/exist.txt")
assert.NoError(t, err, "Failed to parse namespace")
assert.Equal(t, "", ns.Path)
assert.Equal(t, Namespace{}.UseTokenOnRead, ns.UseTokenOnRead)
// Check for not private
ns, err = MatchNamespace("/osgconnect/public/path/to/file.txt")
assert.NoError(t, err, "Failed to parse namespace")
assert.Equal(t, "/osgconnect", ns.Path)
assert.Equal(t, false, ns.ReadHTTPS)
assert.Equal(t, false, ns.UseTokenOnRead)
}