1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-20 00:18:12 +08:00
Files
kubo/core/commands/get_test.go
Steven Allen 5f64b270f8 cmdkit -> cmds
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2019-05-10 23:00:20 -07:00

69 lines
1.5 KiB
Go

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)
}
})
}
}