avoid using the TODO context in tests
Instead, properly create and cancel the context. (also, use subtests) License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Jan 10, 2018 at 17:34 UTC
d256c5ba38ce807ff820daffd31a51efa37c3545
1 file changed
+15
-8
core/commands/get_test.go
+15
-8
@@ -2,6 +2,7 @@ package commands
2
3
import (
4
"context"
5
+ "fmt"
6
"testing"
7
8
cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
@@ -50,13 +51,19 @@ func TestGetOutputPath(t *testing.T) {
51
t.Fatalf("error getting default command options: %v", err)
52
}
53
53
- for _, tc := range cases {
54
- req, err := cmds.NewRequest(context.TODO(), []string{}, tc.opts, tc.args, nil, GetCmd)
55
- if err != nil {
56
- t.Fatalf("error creating a command request: %v", err)
57
- }
58
- if outPath := getOutPath(req); outPath != tc.outPath {
59
- t.Errorf("expected outPath %s to be %s", outPath, tc.outPath)
60
- }
54
+ for i, tc := range cases {
55
+ t.Run(fmt.Sprintf("%s-%d", t.Name(), i), func(t *testing.T) {
56
+ ctx, cancel := context.WithCancel(context.Background())
57
+ defer cancel()
58
+
59
+ req, err := cmds.NewRequest(ctx, []string{}, tc.opts, tc.args, nil, GetCmd)
60
+ if err != nil {
61
+ t.Fatalf("error creating a command request: %v", err)
62
+ }
63
+
64
+ if outPath := getOutPath(req); outPath != tc.outPath {
65
+ t.Errorf("expected outPath %s to be %s", outPath, tc.outPath)
66
+ }
67
+ })
68
}
69
}