Skip to content

Commit

Permalink
use subtests and defer in TestSPDYExecutorStream
Browse files Browse the repository at this point in the history
Signed-off-by: arkbriar <[email protected]>

Kubernetes-commit: 86e5d069ecece8591ad693b50bcea49000f6df26
  • Loading branch information
arkbriar authored and k8s-publishing-bot committed Oct 10, 2022
1 parent 5e0a531 commit 2362c7b
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions tools/remotecommand/remotecommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,29 +157,27 @@ func TestSPDYExecutorStream(t *testing.T) {
}

for _, test := range tests {
server := newTestHTTPServer(test.attacher, &test.options)
t.Run(test.name, func(t *testing.T) {
server := newTestHTTPServer(test.attacher, &test.options)
defer server.Close()

ctx, cancelFn := context.Background(), func() {}
if test.timeout > 0 {
ctx, cancelFn = context.WithTimeout(ctx, test.timeout)
}
ctx, cancel := context.Background(), func() {}
if test.timeout > 0 {
ctx, cancel = context.WithTimeout(ctx, test.timeout)
}
defer cancel()

err := func(ctx context.Context, cancel context.CancelFunc) error {
defer cancelFn()
return attach2Server(ctx, server.URL, test.options)
}(ctx, cancelFn)
err := attach2Server(ctx, server.URL, test.options)

gotError := ""
if err != nil {
gotError = err.Error()
}
if test.expectError != gotError {
t.Errorf("%s: expected [%v], got [%v]", test.name, test.expectError, gotError)
}

server.Close()
gotError := ""
if err != nil {
gotError = err.Error()
}
if test.expectError != gotError {
t.Errorf("%s: expected [%v], got [%v]", test.name, test.expectError, gotError)
}
})
}

}

func newTestHTTPServer(f AttachFunc, options *StreamOptions) *httptest.Server {
Expand Down

0 comments on commit 2362c7b

Please sign in to comment.