forked from aws/aws-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eventstream: adds middleware to close input-writer in case of error (a…
…ws#3867) * eventream template change: add unmarshal error handler to close inputWriter io.writer in case of an error for the first connection request * make generate changes * hand-written unit test to test for error case io.write resource is freed * remove dead code * bug fix: set original error for validate response handler error * use awserr error type for any error occuring when closing input writer for eventstream * use ioutil.NopCloser instead of io.NopCloser to satisfy older go versions * use anonymous creds for test * eventstream: update template for code gen * update test and generate service clients
- Loading branch information
1 parent
e8bafb8
commit d265de1
Showing
8 changed files
with
150 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// +build go1.10 | ||
|
||
package transcribestreamingservice | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
) | ||
|
||
type roundTripFunc func(req *http.Request) *http.Response | ||
|
||
func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { | ||
return f(req), nil | ||
} | ||
|
||
func newTestClient(fn roundTripFunc) *http.Client { | ||
return &http.Client{ | ||
Transport: fn, | ||
} | ||
} | ||
|
||
func TestStartStreamTranscription_Error(t *testing.T) { | ||
cfg := &aws.Config{ | ||
Region: aws.String("us-west-2"), | ||
Credentials: credentials.AnonymousCredentials, | ||
HTTPClient: newTestClient(func(req *http.Request) *http.Response { | ||
return &http.Response{ | ||
StatusCode: http.StatusBadRequest, | ||
Body: ioutil.NopCloser(bytes.NewReader([]byte("{ \"code\" : \"BadRequestException\" }"))), | ||
Header: http.Header{}, | ||
} | ||
}), | ||
} | ||
sess, err := session.NewSession(cfg) | ||
|
||
svc := New(sess) | ||
resp, err := svc.StartStreamTranscription(&StartStreamTranscriptionInput{ | ||
LanguageCode: aws.String(LanguageCodeEnUs), | ||
MediaEncoding: aws.String(MediaEncodingPcm), | ||
MediaSampleRateHertz: aws.Int64(int64(16000)), | ||
}) | ||
if err == nil { | ||
t.Fatalf("expect error, got none") | ||
} else { | ||
if e, a := "BadRequestException", err.Error(); !strings.Contains(a, e) { | ||
t.Fatalf("expected error to be %v, got %v", e, a) | ||
} | ||
} | ||
|
||
n, err := resp.GetStream().inputWriter.Write([]byte("text")) | ||
if err == nil { | ||
t.Fatalf("expected error stating write on closed pipe, got none") | ||
} | ||
|
||
if e, a := "write on closed pipe", err.Error(); !strings.Contains(a, e) { | ||
t.Fatalf("expected error to contain %v, got error as %v", e, a) | ||
} | ||
|
||
if e, a := 0, n; e != a { | ||
t.Fatalf("expected %d bytes to be written on inputWriter, but %v bytes were written", e, a) | ||
} | ||
} |