From d256c5ba38ce807ff820daffd31a51efa37c3545 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 10 Jan 2018 17:34:08 -0800 Subject: [PATCH] avoid using the TODO context in tests Instead, properly create and cancel the context. (also, use subtests) License: MIT Signed-off-by: Steven Allen --- core/commands/get_test.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/commands/get_test.go b/core/commands/get_test.go index 2cf930725..929ebf569 100644 --- a/core/commands/get_test.go +++ b/core/commands/get_test.go @@ -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) + } + }) } }