mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
use subtests and defer in TestSPDYExecutorStream
Signed-off-by: arkbriar <arkbriar@gmail.com>
This commit is contained in:
parent
42808c8343
commit
86e5d069ec
@ -157,29 +157,27 @@ func TestSPDYExecutorStream(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
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() {}
|
ctx, cancel := context.Background(), func() {}
|
||||||
if test.timeout > 0 {
|
if test.timeout > 0 {
|
||||||
ctx, cancelFn = context.WithTimeout(ctx, test.timeout)
|
ctx, cancel = context.WithTimeout(ctx, test.timeout)
|
||||||
}
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
err := func(ctx context.Context, cancel context.CancelFunc) error {
|
err := attach2Server(ctx, server.URL, test.options)
|
||||||
defer cancelFn()
|
|
||||||
return attach2Server(ctx, server.URL, test.options)
|
|
||||||
}(ctx, cancelFn)
|
|
||||||
|
|
||||||
gotError := ""
|
gotError := ""
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotError = err.Error()
|
gotError = err.Error()
|
||||||
}
|
}
|
||||||
if test.expectError != gotError {
|
if test.expectError != gotError {
|
||||||
t.Errorf("%s: expected [%v], got [%v]", test.name, test.expectError, gotError)
|
t.Errorf("%s: expected [%v], got [%v]", test.name, test.expectError, gotError)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
server.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestHTTPServer(f AttachFunc, options *StreamOptions) *httptest.Server {
|
func newTestHTTPServer(f AttachFunc, options *StreamOptions) *httptest.Server {
|
||||||
|
Loading…
Reference in New Issue
Block a user