Skip to content

Commit

Permalink
Linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibiscum committed Feb 16, 2024
1 parent 0b1f065 commit 48ec2ca
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
6 changes: 5 additions & 1 deletion cmd/Chapter07/Exercise07.03/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log"
"testing"
)

Expand Down Expand Up @@ -36,7 +37,10 @@ func TestNewRecord(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
got := newRecord(tc.inputKey, tc.inputInterface)
if got.key != tc.wanted.key {
fmt.Errorf("Got: %v wanted %v", got, tc.wanted.key)
err := fmt.Errorf("Got: %v wanted %v", got, tc.wanted.key)
if err != nil {
log.Fatal(err)
}

}
})
Expand Down
6 changes: 5 additions & 1 deletion cmd/Chapter15/Activity15.02/a15.02.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ func (h *PageWithCounter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(400)
return
}
w.Write([]byte(bts))
_, err = w.Write([]byte(bts))
if err != nil {
log.Fatal(err)
}

}

func main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ func (h Hello) ServeHTTP(w http.ResponseWriter, r *http.Request) {

cust := Visitor{}


name, ok := vl["name"]
if ok {
cust.Name = strings.Join(name, ",")
}

h.tpl.Execute(w, cust)
err := h.tpl.Execute(w, cust)
if err != nil {
log.Fatal(err)
}
}

// NewHello returns a new Hello handler
func NewHello(tplPath string) (*Hello, error){
func NewHello(tplPath string) (*Hello, error) {
tmpl, err := template.ParseFiles(tplPath)
if err != nil {
return nil, err
Expand All @@ -46,4 +48,4 @@ func main() {
http.Handle("/", hello)

log.Fatal(http.ListenAndServe(":8080", nil))
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package main

import (
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
"os"
"testing"
)

func Test_name(t *testing.T) {
hdl, err := NewHello("./index.html")
if err != nil {
Expand All @@ -15,14 +19,17 @@ func Test_name(t *testing.T) {
if err != nil {
t.Error(err)
}
expected, err := ioutil.ReadFile("./teststatics/john.html")
expected, err := os.ReadFile("./teststatics/john.html")
if err != nil {
t.Error(err)
}
actual := make([]byte, rsp.ContentLength)
rsp.Body.Read(actual)
if string(actual)!= string(expected) {
t.Errorf("\n%s\n%s", string(expected),string(actual))
_, err = rsp.Body.Read(actual)
if err != io.EOF {
log.Fatal(err)
}
if string(actual) != string(expected) {
t.Errorf("\n%s\n%s", string(expected), string(actual))
}
}

Expand All @@ -36,13 +43,13 @@ func Test_anonymous(t *testing.T) {
if err != nil {
t.Error(err)
}
expected, err := ioutil.ReadFile("./teststatics/anonymous.html")
expected, err := os.ReadFile("./teststatics/anonymous.html")
if err != nil {
t.Error(err)
}
actual := make([]byte, rsp.ContentLength)
rsp.Body.Read(actual)
if string(actual)!= string(expected) {
t.Errorf("\n%s\n%s", string(expected),string(actual))
if string(actual) != string(expected) {
t.Errorf("\n%s\n%s", string(expected), string(actual))
}
}
}

0 comments on commit 48ec2ca

Please sign in to comment.