mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
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>
This commit is contained in:
parent
cddef3ec5e
commit
d256c5ba38
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user