1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-21 00:47:22 +08:00
Files
kubo/core/commands/get_test.go
Dominic Della Valle b675ade0d8 gx: update go-ipfs-cmds
License: MIT
Signed-off-by: Dominic Della Valle <ddvpublic@gmail.com>
2018-04-24 15:01:16 -04:00

70 lines
1.6 KiB
Go

package commands
import (
"context"
"fmt"
"testing"
cmds "gx/ipfs/QmTjNRVt2fvaRFu93keEC7z5M1GS1iH6qZ9227htQioTUY/go-ipfs-cmds"
cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
)
func TestGetOutputPath(t *testing.T) {
cases := []struct {
args []string
opts cmdkit.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: cmdkit.OptMap{
"output": "takes-precedence",
},
outPath: "takes-precedence",
},
{
args: []string{"/ipns/multiformats.io/"},
outPath: "multiformats.io",
opts: cmdkit.OptMap{},
},
{
args: []string{"/ipns/multiformats.io/logo.svg/"},
outPath: "logo.svg",
opts: cmdkit.OptMap{},
},
{
args: []string{"/ipns/multiformats.io", "some-other-arg-to-be-ignored"},
outPath: "multiformats.io",
opts: cmdkit.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)
}
})
}
}