Skip to content

Commit

Permalink
Merge pull request #1456 from AkihiroSuda/fix-test-failures
Browse files Browse the repository at this point in the history
Fix test failures
  • Loading branch information
aboch authored Sep 22, 2016
2 parents f4de3a4 + 37027b4 commit 6dd4176
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 11 additions & 5 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1667,9 +1667,8 @@ func (f *localResponseWriter) WriteHeader(c int) {
f.statusCode = c
}

func TestwriteJSON(t *testing.T) {
testCode := 55
testData, err := json.Marshal("test data")
func testWriteJSON(t *testing.T, testCode int, testData interface{}) {
testDataMarshalled, err := json.Marshal(testData)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1679,10 +1678,17 @@ func TestwriteJSON(t *testing.T) {
if rsp.statusCode != testCode {
t.Fatalf("writeJSON() failed to set the status code. Expected %d. Got %d", testCode, rsp.statusCode)
}
if !bytes.Equal(testData, rsp.body) {
t.Fatalf("writeJSON() failed to set the body. Expected %s. Got %s", testData, rsp.body)
// writeJSON calls json.Encode and it appends '\n' to the result,
// while json.Marshal not
expected := append(testDataMarshalled, byte('\n'))
if !bytes.Equal(expected, rsp.body) {
t.Fatalf("writeJSON() failed to set the body. Expected %q. Got %q", expected, rsp.body)
}
}

func TestWriteJSON(t *testing.T) {
testWriteJSON(t, 55, "test data as string")
testWriteJSON(t, 55, []byte("test data as bytes"))
}

func TestHttpHandlerUninit(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions libnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ func TestLeaveAll(t *testing.T) {
}
}

func TestontainerInvalidLeave(t *testing.T) {
func TestContainerInvalidLeave(t *testing.T) {
if !testutils.IsRunningInContainer() {
defer testutils.SetupTestOSContext(t)()
}
Expand Down Expand Up @@ -1595,19 +1595,19 @@ func TestontainerInvalidLeave(t *testing.T) {
t.Fatalf("Failed with unexpected error type: %T. Desc: %s", err, err.Error())
}

if err := ep.Leave(nil); err == nil {
if err = ep.Leave(nil); err == nil {
t.Fatalf("Expected to fail leave nil Sandbox")
}
if _, ok := err.(types.BadRequestError); !ok {
t.Fatalf("Unexpected error type returned: %T", err)
t.Fatalf("Unexpected error type returned: %T. Desc: %s", err, err.Error())
}

fsbx := &fakeSandbox{}
if err = ep.Leave(fsbx); err == nil {
t.Fatalf("Expected to fail leave with invalid Sandbox")
}
if _, ok := err.(types.BadRequestError); !ok {
t.Fatalf("Unexpected error type returned: %T", err)
t.Fatalf("Unexpected error type returned: %T. Desc: %s", err, err.Error())
}
}

Expand Down

0 comments on commit 6dd4176

Please sign in to comment.