Skip to content

Commit 60b3878

Browse files
Edits thanks to Bill Hathaway's review.
1 parent 91341c6 commit 60b3878

5 files changed

Lines changed: 18 additions & 16 deletions

File tree

‎chapter9/listing03/listing03_test.go‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,26 @@ func TestDownload(t *testing.T) {
8989

9090
defer resp.Body.Close()
9191

92-
if resp.StatusCode == statusCode {
93-
t.Logf("\t\tShould receive a \"%d\" status code. %v",
94-
statusCode, checkMark)
95-
} else {
96-
t.Errorf("\t\tShould receive a \"%d\" status code. %v %v",
92+
if resp.StatusCode != statusCode {
93+
t.Fatalf("\t\tShould receive a \"%d\" status code. %v %v",
9794
statusCode, ballotX, resp.StatusCode)
9895
}
96+
t.Logf("\t\tShould receive a \"%d\" status code. %v",
97+
statusCode, checkMark)
9998

10099
var d Document
101-
if err := xml.NewDecoder(resp.Body).Decode(&d); err == nil {
102-
t.Log("\t\tShould be able to unmarshal the response.",
103-
checkMark)
104-
} else {
100+
if err := xml.NewDecoder(resp.Body).Decode(&d); err != nil {
105101
t.Fatal("\t\tShould be able to unmarshal the response.",
106102
ballotX, err)
107103
}
104+
t.Log("\t\tShould be able to unmarshal the response.",
105+
checkMark)
108106

109107
if len(d.Channel.Items) == 1 {
110108
t.Log("\t\tShould have \"1\" item in the feed.",
111109
checkMark)
112110
} else {
113-
t.Fatal("\t\tShould have \"1\" item in the feed.",
111+
t.Error("\t\tShould have \"1\" item in the feed.",
114112
ballotX, len(d.Channel.Items))
115113
}
116114
}

‎chapter9/listing04/example04.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func SendJSON(rw http.ResponseWriter, r *http.Request) {
3737
// We want this error condition to panic so we get a stack trace. This should
3838
// never happen. The http package will catch the panic and provide logging
3939
// and return a 500 back to the caller.
40-
log.Panic("Unable to unmatshal response", err)
40+
log.Panic("Unable to unmarshal response", err)
4141
}
4242

4343
datalen := len(data) + 1 // account for trailing LF

‎chapter9/listing04/example04_example_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func ExampleSendJSON() {
2828
log.Println("ERROR:", err)
2929
}
3030

31+
// Use fmt to write to stdout to check the output.
3132
fmt.Println(u)
3233
// Output:
3334
// {Bill bill@ardanstudios.com}

‎chapter9/listing04/example04_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ func TestSendJSON(t *testing.T) {
2626
http.DefaultServeMux.ServeHTTP(w, r)
2727

2828
if w.Code != 200 {
29-
t.Fatalf("\tShould received a status code of 200 for the response. Received[%d] %s", w.Code, ballotX)
29+
t.Fatalf("\tShould receive a status code of 200 for the response. Received[%d] %s", w.Code, ballotX)
3030
}
31-
t.Log("\tShould received a status code of 200 for the response.", checkMark)
31+
t.Log("\tShould receive a status code of 200 for the response.", checkMark)
3232

3333
u := struct {
3434
Name string
3535
Email string
3636
}{}
3737
if err := json.NewDecoder(w.Body).Decode(&u); err != nil {
38-
t.Fatal("\tShould be able to unmarshal the response.", ballotX)
38+
t.Fatal("\tShould be able to decode the response.", ballotX)
3939
}
40-
t.Log("\tShould be able to unmarshal the response.", checkMark)
40+
t.Log("\tShould be able to decode the response.", checkMark)
4141

4242
if u.Name == "Bill" {
4343
t.Log("\tShould have \"Bill\" for Name in the response.", checkMark)

‎chapter9/listing05/listing05.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// matrix in different ways.
33
package listing05
44

5+
import "fmt"
6+
57
const cols = 64
68

79
// Set the size of each row to be 64k.
@@ -22,7 +24,8 @@ func init() {
2224
}
2325
}
2426
}
25-
println(ctr, "Elements set out of", cols*rows)
27+
28+
fmt.Println(ctr, "Elements set out of", cols*rows)
2629
}
2730

2831
// rowTraverse traverses the matrix linearly by each column for each row.

0 commit comments

Comments
 (0)