Skip to content

Commit 6dd4176

Browse files
authored
Merge pull request #1456 from AkihiroSuda/fix-test-failures
Fix test failures
2 parents f4de3a4 + 37027b4 commit 6dd4176

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

api/api_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,9 +1667,8 @@ func (f *localResponseWriter) WriteHeader(c int) {
16671667
f.statusCode = c
16681668
}
16691669

1670-
func TestwriteJSON(t *testing.T) {
1671-
testCode := 55
1672-
testData, err := json.Marshal("test data")
1670+
func testWriteJSON(t *testing.T, testCode int, testData interface{}) {
1671+
testDataMarshalled, err := json.Marshal(testData)
16731672
if err != nil {
16741673
t.Fatal(err)
16751674
}
@@ -1679,10 +1678,17 @@ func TestwriteJSON(t *testing.T) {
16791678
if rsp.statusCode != testCode {
16801679
t.Fatalf("writeJSON() failed to set the status code. Expected %d. Got %d", testCode, rsp.statusCode)
16811680
}
1682-
if !bytes.Equal(testData, rsp.body) {
1683-
t.Fatalf("writeJSON() failed to set the body. Expected %s. Got %s", testData, rsp.body)
1681+
// writeJSON calls json.Encode and it appends '\n' to the result,
1682+
// while json.Marshal not
1683+
expected := append(testDataMarshalled, byte('\n'))
1684+
if !bytes.Equal(expected, rsp.body) {
1685+
t.Fatalf("writeJSON() failed to set the body. Expected %q. Got %q", expected, rsp.body)
16841686
}
1687+
}
16851688

1689+
func TestWriteJSON(t *testing.T) {
1690+
testWriteJSON(t, 55, "test data as string")
1691+
testWriteJSON(t, 55, []byte("test data as bytes"))
16861692
}
16871693

16881694
func TestHttpHandlerUninit(t *testing.T) {

libnetwork_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ func TestLeaveAll(t *testing.T) {
15451545
}
15461546
}
15471547

1548-
func TestontainerInvalidLeave(t *testing.T) {
1548+
func TestContainerInvalidLeave(t *testing.T) {
15491549
if !testutils.IsRunningInContainer() {
15501550
defer testutils.SetupTestOSContext(t)()
15511551
}
@@ -1595,19 +1595,19 @@ func TestontainerInvalidLeave(t *testing.T) {
15951595
t.Fatalf("Failed with unexpected error type: %T. Desc: %s", err, err.Error())
15961596
}
15971597

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

16051605
fsbx := &fakeSandbox{}
16061606
if err = ep.Leave(fsbx); err == nil {
16071607
t.Fatalf("Expected to fail leave with invalid Sandbox")
16081608
}
16091609
if _, ok := err.(types.BadRequestError); !ok {
1610-
t.Fatalf("Unexpected error type returned: %T", err)
1610+
t.Fatalf("Unexpected error type returned: %T. Desc: %s", err, err.Error())
16111611
}
16121612
}
16131613

0 commit comments

Comments
 (0)