forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_test.go
68 lines (61 loc) · 1.5 KB
/
get_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package commands
import (
"context"
"fmt"
"testing"
cmds "github.com/ipfs/go-ipfs-cmds"
)
func TestGetOutputPath(t *testing.T) {
cases := []struct {
args []string
opts cmds.OptMap
outPath string
}{
{
args: []string{"/ipns/multiformats.io/"},
opts: map[string]interface{}{
"output": "takes-precedence",
},
outPath: "takes-precedence",
},
{
args: []string{"/ipns/multiformats.io/", "some-other-arg-to-be-ignored"},
opts: cmds.OptMap{
"output": "takes-precedence",
},
outPath: "takes-precedence",
},
{
args: []string{"/ipns/multiformats.io/"},
outPath: "multiformats.io",
opts: cmds.OptMap{},
},
{
args: []string{"/ipns/multiformats.io/logo.svg/"},
outPath: "logo.svg",
opts: cmds.OptMap{},
},
{
args: []string{"/ipns/multiformats.io", "some-other-arg-to-be-ignored"},
outPath: "multiformats.io",
opts: cmds.OptMap{},
},
}
_, err := GetCmd.GetOptions([]string{})
if err != nil {
t.Fatalf("error getting default command options: %v", err)
}
for i, tc := range cases {
t.Run(fmt.Sprintf("%s-%d", t.Name(), i), func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
req, err := cmds.NewRequest(ctx, []string{}, tc.opts, tc.args, nil, GetCmd)
if err != nil {
t.Fatalf("error creating a command request: %v", err)
}
if outPath := getOutPath(req); outPath != tc.outPath {
t.Errorf("expected outPath %s to be %s", outPath, tc.outPath)
}
})
}
}