Last active
December 24, 2015 17:28
-
-
Save divoxx/6835218 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- FAIL: TestUpdateUser (0.00 seconds) | |
panic: illegal base64 data at input byte 0 [recovered] | |
panic: illegal base64 data at input byte 0 | |
goroutine 4 [running]: | |
testing.func·004() | |
/usr/local/Cellar/go/1.1.2/libexec/src/pkg/testing/testing.go:348 +0xcd | |
github.com/doximity/auth-api/foo.UpdateUser(0xc2000b0c40, 0xc2000c14c0, 0xc2000b1410) | |
/Users/divoxx/Projects/gopath/src/github.com/doximity/auth-api/foo/foo.go:26 +0x122 | |
net/http.HandlerFunc.ServeHTTP(0x2d2398, 0xc2000b0c40, 0xc2000c14c0, 0xc2000b1410) | |
/usr/local/Cellar/go/1.1.2/libexec/src/pkg/net/http/server.go:1149 +0x3e | |
net/http.(*ServeMux).ServeHTTP(0xc2000af6c0, 0xc2000b0c40, 0xc2000c14c0, 0xc2000b1410) | |
/usr/local/Cellar/go/1.1.2/libexec/src/pkg/net/http/server.go:1416 +0x11d | |
github.com/doximity/auth-api/foo.TestUpdateUser(0xc2000c2000) | |
/Users/divoxx/Projects/gopath/src/github.com/doximity/auth-api/foo/foo_test.go:22 +0x278 | |
testing.tRunner(0xc2000c2000, 0x3d7c90) | |
/usr/local/Cellar/go/1.1.2/libexec/src/pkg/testing/testing.go:353 +0x8a | |
created by testing.RunTests | |
/usr/local/Cellar/go/1.1.2/libexec/src/pkg/testing/testing.go:433 +0x86b | |
goroutine 1 [chan receive]: | |
testing.RunTests(0x2d23a8, 0x3d7c90, 0x1, 0x1, 0x1, ...) | |
/usr/local/Cellar/go/1.1.2/libexec/src/pkg/testing/testing.go:434 +0x88e | |
testing.Main(0x2d23a8, 0x3d7c90, 0x1, 0x1, 0x3e0780, ...) | |
/usr/local/Cellar/go/1.1.2/libexec/src/pkg/testing/testing.go:365 +0x8a | |
main.main() | |
github.com/doximity/auth-api/foo/_test/_testmain.go:43 +0x9a | |
goroutine 2 [syscall]: | |
exit status 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"log" | |
"net/http" | |
) | |
func init() { | |
http.HandleFunc("/users", UpdateUser) | |
} | |
func main() { | |
log.Fatal(http.ListenAndServe(":9000", nil)) | |
} | |
type AdminUserResource struct { | |
Email string `json:"email"` | |
CryptedPassword []byte `json:"crypted_password"` | |
} | |
func UpdateUser(w http.ResponseWriter, req *http.Request) { | |
r := AdminUserResource{} | |
if err := json.NewDecoder(req.Body).Decode(&r); err != nil { | |
panic(err) | |
} | |
w.WriteHeader(http.StatusOK) | |
if err := json.NewEncoder(w).Encode(r); err != nil { | |
panic(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"io/ioutil" | |
"net/http" | |
"net/http/httptest" | |
"net/url" | |
"testing" | |
) | |
func TestUpdateUser(t *testing.T) { | |
w := httptest.NewRecorder() | |
b := bytes.NewBufferString(`{"crypted_password": "$2a$10$q93WWJ0MAEIQ.pLRqqkZ1.YQ/UHLG8AC044Vn/BZOO8lsXDCzmOOy"}`) | |
req := &http.Request{ | |
Method: "POST", | |
URL: &url.URL{Path: "/users"}, | |
Body: ioutil.NopCloser(b), | |
} | |
http.DefaultServeMux.ServeHTTP(w, req) | |
rb := w.Body.String() | |
if rb != "" { | |
t.Error(rb) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment