Merge lp:~chipaca/snapweb/www-tests into lp:~snappy-dev/snapweb/trunk

Proposed by John Lenton on 2015-05-06
Status: Superseded
Proposed branch: lp:~chipaca/snapweb/www-tests
Merge into: lp:~snappy-dev/snapweb/trunk
Diff against target: 177 lines (+45/-25)
3 files modified
README.md (+7/-6)
run-checks (+5/-1)
snappy/handlers.go (+33/-18)
To merge this branch: bzr merge lp:~chipaca/snapweb/www-tests
Reviewer Review Type Date Requested Status
Sergio Schvezov 2015-05-06 Approve on 2015-05-06
Review via email: mp+258325@code.launchpad.net

This proposal has been superseded by a proposal from 2015-05-06.

Commit Message

Run js unit tests from run-checks.

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

Looks good, but add the prereq ;-)

review: Approve
lp:~chipaca/snapweb/www-tests updated on 2015-05-06
115. By John Lenton on 2015-05-06

provide a way to override the js test runner

116. By John Lenton on 2015-05-06

silly chipaca is silly

Unmerged revisions

116. By John Lenton on 2015-05-06

silly chipaca is silly

115. By John Lenton on 2015-05-06

provide a way to override the js test runner

114. By John Lenton on 2015-05-05

run js unit tests from run-checks

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.md'
2--- README.md 2015-04-29 15:01:08 +0000
3+++ README.md 2015-05-06 00:06:22 +0000
4@@ -9,15 +9,16 @@
5
6 Install global npm modules without sudo:
7
8- cat > ~/.npmrc << EOF
9- root = $HOME/node/lib/node_modules
10- prefix = $HOME/node
11- binroot = $HOME/node/bin
12- manroot = $HOME/node/man
13- EOF
14+ cat > ~/.npmrc <<-EOF
15+ root = $HOME/node/lib/node_modules
16+ prefix = $HOME/node
17+ binroot = $HOME/node/bin
18+ manroot = $HOME/node/man
19+ EOF
20
21 Setup the environment:
22
23+ mkdir ~/node
24 export PATH=$PATH:$HOME/node/bin
25 export NODE_PATH=$HOME/node/lib/node_modules
26
27
28=== modified file 'run-checks'
29--- run-checks 2015-05-03 20:46:35 +0000
30+++ run-checks 2015-05-06 00:06:22 +0000
31@@ -43,7 +43,7 @@
32 echo Running vet
33 go vet ./...
34
35- golint
36+# golint
37 echo Running lint
38 lint=$(golint ./...)
39 if [ -n "$lint" ]; then
40@@ -52,4 +52,8 @@
41 exit 1
42 fi
43
44+# js unit tests
45+echo Running js unit tests
46+( cd www && xvfb-run ./node_modules/karma/bin/karma start --single-run )
47+
48 echo "All good, what could possibly go wrong"
49
50=== modified file 'snappy/handlers.go'
51--- snappy/handlers.go 2015-05-03 20:35:34 +0000
52+++ snappy/handlers.go 2015-05-06 00:06:22 +0000
53@@ -21,10 +21,9 @@
54 "encoding/json"
55 "fmt"
56 "io"
57+ "log"
58 "net/http"
59
60- "log"
61-
62 "launchpad.net/snappy/snappy"
63 "launchpad.net/webdm/webprogress"
64
65@@ -44,80 +43,96 @@
66 }
67
68 func (h *Handler) getAll(w http.ResponseWriter, r *http.Request) {
69+ w.Header().Set("Content-Type", "application/json")
70+ enc := json.NewEncoder(w)
71 dec := json.NewDecoder(r.Body)
72
73 var filter listFilter
74 if err := dec.Decode(&filter); err != nil && err != io.EOF {
75 w.WriteHeader(http.StatusInternalServerError)
76- fmt.Fprint(w, fmt.Sprintf("Error: %s", err))
77+ enc.Encode(fmt.Sprintf("Error: %s", err))
78 return
79 }
80
81 payload, err := h.allPackages(filter.InstalledOnly)
82 if err != nil {
83 w.WriteHeader(http.StatusInternalServerError)
84- fmt.Fprint(w, fmt.Sprintf("Error: %s", err))
85+ enc.Encode(fmt.Sprintf("Error: %s", err))
86 return
87 }
88
89- enc := json.NewEncoder(w)
90 if err := enc.Encode(payload); err != nil {
91 w.WriteHeader(http.StatusInternalServerError)
92- fmt.Fprint(w, fmt.Sprintf("Error: %s", err))
93- return
94+ // give up on json
95+ fmt.Fprintf(w, "Error: %s", err)
96+ log.Print(err)
97 }
98 }
99
100 func (h *Handler) get(w http.ResponseWriter, r *http.Request) {
101+ w.Header().Set("Content-Type", "application/json")
102 // Get the Key.
103 vars := mux.Vars(r)
104 pkgName := vars["pkg"]
105+ enc := json.NewEncoder(w)
106
107 payload, err := h.packagePayload(pkgName)
108 if err != nil {
109- http.NotFound(w, r)
110- fmt.Fprintln(w, err, pkgName)
111+ w.WriteHeader(http.StatusNotFound)
112+ // http.NotFound(w, r)
113+ enc.Encode(fmt.Sprintln(err, pkgName))
114 return
115 }
116
117- enc := json.NewEncoder(w)
118 if err := enc.Encode(payload); err != nil {
119- fmt.Fprint(w, "Error")
120+ w.WriteHeader(http.StatusInternalServerError)
121+ // give up on json
122+ fmt.Fprintf(w, "Error: %s", err)
123+ log.Print(err)
124 }
125 }
126
127 func (h *Handler) add(w http.ResponseWriter, r *http.Request) {
128+ w.Header().Set("Content-Type", "application/json")
129 // Get the Key.
130 vars := mux.Vars(r)
131 pkgName := vars["pkg"]
132
133- enc := json.NewEncoder(w)
134 var msg string
135+ var status int
136
137 err := h.installPackage(pkgName)
138
139 switch err {
140 case snappy.ErrAlreadyInstalled:
141- w.WriteHeader(http.StatusOK)
142+ status = http.StatusOK
143 msg = "Installed"
144 case webprogress.ErrPackageInstallInProgress:
145- w.WriteHeader(http.StatusBadRequest)
146+ status = http.StatusBadRequest
147 msg = "Installation in progress"
148 case snappy.ErrPackageNotFound:
149- w.WriteHeader(http.StatusNotFound)
150+ status = http.StatusNotFound
151 msg = "Package not found"
152 case nil:
153- w.WriteHeader(http.StatusAccepted)
154+ status = http.StatusAccepted
155 msg = "Accepted"
156 default:
157- w.WriteHeader(http.StatusInternalServerError)
158+ status = http.StatusInternalServerError
159 msg = "Processing error"
160 }
161
162 response := response{Message: msg, Package: pkgName}
163- if err := enc.Encode(response); err != nil {
164+ bs, err := json.Marshal(response)
165+ if err != nil {
166+ // giving up on json
167+ w.WriteHeader(http.StatusInternalServerError)
168+ fmt.Fprintf(w, "Error: %s", err)
169 log.Print(err)
170+ return
171 }
172+
173+ w.WriteHeader(status)
174+ w.Write(bs)
175 }
176
177 // MakeMuxer sets up the handlers multiplexing to handle requests against snappy's

Subscribers

People subscribed via source and target branches

to all changes: