提交 d256c5ba 作者: Steven Allen 提交者: Jeromy

avoid using the TODO context in tests

Instead, properly create and cancel the context.

(also, use subtests)

License: MIT
Signed-off-by: 's avatarSteven Allen <steven@stebalien.com>
上级 cddef3ec
......@@ -2,6 +2,7 @@ package commands
import (
"context"
"fmt"
"testing"
cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
......@@ -50,13 +51,19 @@ func TestGetOutputPath(t *testing.T) {
t.Fatalf("error getting default command options: %v", err)
}
for _, tc := range cases {
req, err := cmds.NewRequest(context.TODO(), []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)
}
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)
}
})
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论