Commit d256c5ba authored by Steven Allen's avatar Steven Allen Committed by Jeromy

avoid using the TODO context in tests

Instead, properly create and cancel the context.

(also, use subtests)

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent 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 is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment