* TestwriteJSON and TestontainerInvalidLeave were never executed due to the typos. Recent govet found them.
* TestWriteJSON was failing due to the comparison between string and []byte. Also, it didn't considered that json.Encode appends LF.
* TestContainerInvalidLeave was faling due to a typo
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
| ... | ... |
@@ -1667,9 +1667,8 @@ func (f *localResponseWriter) WriteHeader(c int) {
|
| 1667 | 1667 |
f.statusCode = c |
| 1668 | 1668 |
} |
| 1669 | 1669 |
|
| 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) |
|
| 1673 | 1672 |
if err != nil {
|
| 1674 | 1673 |
t.Fatal(err) |
| 1675 | 1674 |
} |
| ... | ... |
@@ -1679,10 +1678,17 @@ func TestwriteJSON(t *testing.T) {
|
| 1679 | 1679 |
if rsp.statusCode != testCode {
|
| 1680 | 1680 |
t.Fatalf("writeJSON() failed to set the status code. Expected %d. Got %d", testCode, rsp.statusCode)
|
| 1681 | 1681 |
} |
| 1682 |
- if !bytes.Equal(testData, rsp.body) {
|
|
| 1683 |
- t.Fatalf("writeJSON() failed to set the body. Expected %s. Got %s", testData, rsp.body)
|
|
| 1682 |
+ // writeJSON calls json.Encode and it appends '\n' to the result, |
|
| 1683 |
+ // while json.Marshal not |
|
| 1684 |
+ expected := append(testDataMarshalled, byte('\n'))
|
|
| 1685 |
+ if !bytes.Equal(expected, rsp.body) {
|
|
| 1686 |
+ t.Fatalf("writeJSON() failed to set the body. Expected %q. Got %q", expected, rsp.body)
|
|
| 1684 | 1687 |
} |
| 1688 |
+} |
|
| 1685 | 1689 |
|
| 1690 |
+func TestWriteJSON(t *testing.T) {
|
|
| 1691 |
+ testWriteJSON(t, 55, "test data as string") |
|
| 1692 |
+ testWriteJSON(t, 55, []byte("test data as bytes"))
|
|
| 1686 | 1693 |
} |
| 1687 | 1694 |
|
| 1688 | 1695 |
func TestHttpHandlerUninit(t *testing.T) {
|
| ... | ... |
@@ -1545,7 +1545,7 @@ func TestLeaveAll(t *testing.T) {
|
| 1545 | 1545 |
} |
| 1546 | 1546 |
} |
| 1547 | 1547 |
|
| 1548 |
-func TestontainerInvalidLeave(t *testing.T) {
|
|
| 1548 |
+func TestContainerInvalidLeave(t *testing.T) {
|
|
| 1549 | 1549 |
if !testutils.IsRunningInContainer() {
|
| 1550 | 1550 |
defer testutils.SetupTestOSContext(t)() |
| 1551 | 1551 |
} |
| ... | ... |
@@ -1595,11 +1595,11 @@ func TestontainerInvalidLeave(t *testing.T) {
|
| 1595 | 1595 |
t.Fatalf("Failed with unexpected error type: %T. Desc: %s", err, err.Error())
|
| 1596 | 1596 |
} |
| 1597 | 1597 |
|
| 1598 |
- if err := ep.Leave(nil); err == nil {
|
|
| 1598 |
+ if err = ep.Leave(nil); err == nil {
|
|
| 1599 | 1599 |
t.Fatalf("Expected to fail leave nil Sandbox")
|
| 1600 | 1600 |
} |
| 1601 | 1601 |
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())
|
|
| 1603 | 1603 |
} |
| 1604 | 1604 |
|
| 1605 | 1605 |
fsbx := &fakeSandbox{}
|
| ... | ... |
@@ -1607,7 +1607,7 @@ func TestontainerInvalidLeave(t *testing.T) {
|
| 1607 | 1607 |
t.Fatalf("Expected to fail leave with invalid Sandbox")
|
| 1608 | 1608 |
} |
| 1609 | 1609 |
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())
|
|
| 1611 | 1611 |
} |
| 1612 | 1612 |
} |
| 1613 | 1613 |
|