octokit / go-octokit

Simple Go wrapper for the GitHub API
https://github.com/octokit/go-octokit
MIT License
258 stars 79 forks source link

Use the latest go-sawyer API #48

Closed owenthereal closed 10 years ago

owenthereal commented 10 years ago

@technoweenie I tried to upgrade to the latest sawyer API and got a couple failed tests. Some of the failure due to the interface{} passed to hypermedia.HyperFiledRelations is a pointer and t.NumFiled() panics for non-struct type. I fixed it in https://github.com/lostisland/go-sawyer/pull/14.

However, there're more failed tests due to passed in type is a slice, for example, the following test to get an array of Authorizations:

--- FAIL: TestAuthorizationsService_All (0.00 seconds)
panic: reflect: NumField of non-struct type [recovered]
        panic: reflect: NumField of non-struct type

goroutine 12 [running]:
runtime.panic(0x22dce0, 0xc21000a8b0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/runtime/panic.c:266 +0xb6
testing.func·005()
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/testing/testing.go:385 +0xe8
runtime.panic(0x22dce0, 0xc21000a8b0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/runtime/panic.c:248 +0x106
reflect.(*rtype).NumField(0x21e7a0, 0x2)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/reflect/type.go:654 +0x6d
github.com/lostisland/go-sawyer/hypermedia.HyperFieldRelations(0x214e60, 0xc210076080, 0xc2100621e0, 0xc21005fa00)
        /Users/owen_ou/gocode/src/github.com/lostisland/go-sawyer/hypermedia/hyperfields.go:28 +0x27a
github.com/lostisland/go-sawyer.(*Response).fillRels(0xc210062210, 0x214e60, 0xc210076080)
        /Users/owen_ou/gocode/src/github.com/lostisland/go-sawyer/response.go:79 +0x7c
github.com/lostisland/go-sawyer.(*Response).Decode(0xc210062210, 0x214e60, 0xc210076080, 0x0, 0x0)
        /Users/owen_ou/gocode/src/github.com/lostisland/go-sawyer/response.go:58 +0x1d0
github.com/jingweno/go-octokit/octokit.(*Request).createResponse(0xc210000610, 0xc210062210, 0x214e60, 0xc210076080, 0xc210076400, ...)
        /Users/owen_ou/gocode/src/github.com/jingweno/go-octokit/octokit/request.go:51 +0x86
github.com/jingweno/go-octokit/octokit.(*Request).Get(0xc210000610, 0x214e60, 0xc210076080, 0x0, 0x0, ...)
        /Users/owen_ou/gocode/src/github.com/jingweno/go-octokit/octokit/request.go:17 +0x56
github.com/jingweno/go-octokit/octokit.func·002(0xc210000610, 0xc21000ae90, 0xe, 0xc210000610)
        /Users/owen_ou/gocode/src/github.com/jingweno/go-octokit/octokit/client.go:43 +0x37
github.com/jingweno/go-octokit/octokit.sendRequest(0xc210062c00, 0xc210068770, 0x77ed58, 0x20)
        /Users/owen_ou/gocode/src/github.com/jingweno/go-octokit/octokit/client.go:115 +0x92
github.com/jingweno/go-octokit/octokit.(*Client).get(0xc210062c00, 0xc210068770, 0x214e60, 0xc210076080, 0x2a6580)
        /Users/owen_ou/gocode/src/github.com/jingweno/go-octokit/octokit/client.go:44 +0x61
github.com/jingweno/go-octokit/octokit.(*AuthorizationsService).All(0xc21000ae80, 0xc21000ae80, 0x0, 0x0, 0x0)
        /Users/owen_ou/gocode/src/github.com/jingweno/go-octokit/octokit/authorizations.go:29 +0x59
github.com/jingweno/go-octokit/octokit.TestAuthorizationsService_All(0xc21004d630)
        /Users/owen_ou/gocode/src/github.com/jingweno/go-octokit/octokit/authorizations_test.go:54 +0x187
testing.tRunner(0xc21004d630, 0x60c9e0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/testing/testing.go:391 +0x8b
created by testing.RunTests
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/testing/testing.go:471 +0x8b2

goroutine 1 [chan receive]:
testing.RunTests(0x38b5c8, 0x60c980, 0x26, 0x26, 0x51b079e987431f01)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/testing/testing.go:472 +0x8d5
testing.Main(0x38b5c8, 0x60c980, 0x26, 0x26, 0x60ef40, ...)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/testing/testing.go:403 +0x84
main.main()
        github.com/jingweno/go-octokit/octokit/_test/_testmain.go:121 +0x9c

goroutine 16 [select]:
net/http.(*persistConn).writeLoop(0xc210058580)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/transport.go:791 +0x271
created by net/http.(*Transport).dialConn
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/transport.go:529 +0x61e

goroutine 17 [runnable]:
net.runtime_pollWait(0x729528, 0x72, 0x0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/runtime/netpoll.goc:116 +0x6a
net.(*pollDesc).Wait(0xc210068e60, 0x72, 0x727f60, 0x23)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/fd_poll_runtime.go:81 +0x34
net.(*pollDesc).WaitRead(0xc210068e60, 0x23, 0x727f60)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/fd_poll_runtime.go:86 +0x30
net.(*netFD).Read(0xc210068e00, 0xc210066000, 0x1000, 0x1000, 0x0, ...)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/fd_unix.go:204 +0x2a0
net.(*conn).Read(0xc210000678, 0xc210066000, 0x1000, 0x1000, 0x0, ...)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/net.go:122 +0xc5
net/http.(*liveSwitchReader).Read(0xc210058628, 0xc210066000, 0x1000, 0x1000, 0x0, ...)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/server.go:204 +0xa5
io.(*LimitedReader).Read(0xc210076260, 0xc210066000, 0x1000, 0x1000, 0x7, ...)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/io/io.go:398 +0xbb
bufio.(*Reader).fill(0xc210037540)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/bufio/bufio.go:91 +0x110
bufio.(*Reader).ReadSlice(0xc210037540, 0x8d20a, 0x0, 0x0, 0x0, ...)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/bufio/bufio.go:274 +0x204
bufio.(*Reader).ReadLine(0xc210037540, 0x0, 0x0, 0x0, 0x0, ...)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/bufio/bufio.go:305 +0x63
net/textproto.(*Reader).readLineSlice(0xc210062ed0, 0x71f000, 0x2216e0, 0x782ce8, 0x21f42, ...)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/textproto/reader.go:55 +0x61
net/textproto.(*Reader).ReadLine(0xc210062ed0, 0xc210044270, 0x0, 0xc210067000, 0x0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/textproto/reader.go:36 +0x27
net/http.ReadRequest(0xc210037540, 0xc210044270, 0x0, 0x0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/request.go:526 +0x88
net/http.(*conn).readRequest(0xc210058600, 0x0, 0x0, 0x0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/server.go:575 +0x1bb
net/http.(*conn).serve(0xc210058600)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/server.go:1123 +0x3b4
created by net/http.(*Server).Serve
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/server.go:1644 +0x28b

goroutine 15 [runnable]:
net/http.(*persistConn).readLoop(0xc210058580)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/transport.go:778 +0x68f
created by net/http.(*Transport).dialConn
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/transport.go:528 +0x607

goroutine 13 [runnable]:
net.runtime_pollWait(0x729480, 0x72, 0x0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/runtime/netpoll.goc:116 +0x6a
net.(*pollDesc).Wait(0xc2100685a0, 0x72, 0x727f60, 0x23)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/fd_poll_runtime.go:81 +0x34
net.(*pollDesc).WaitRead(0xc2100685a0, 0x23, 0x727f60)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/fd_poll_runtime.go:86 +0x30
net.(*netFD).accept(0xc210068540, 0x38d560, 0x0, 0x727f60, 0x23)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/fd_unix.go:382 +0x2c2
net.(*TCPListener).AcceptTCP(0xc2100005e8, 0x1a599, 0x6106f0, 0xc2100525a0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/tcpsock_posix.go:233 +0x47
net.(*TCPListener).Accept(0xc2100005e8, 0x782f98, 0x1a3e3, 0x38d590, 0x77aee8)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/tcpsock_posix.go:243 +0x27
net/http/httptest.(*historyListener).Accept(0xc210062b70, 0x0, 0x0, 0x0, 0x0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/httptest/server.go:48 +0x56
net/http.(*Server).Serve(0xc21001edc0, 0x729678, 0xc210062b70, 0x0, 0x0)
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/server.go:1622 +0x91
created by net/http/httptest.(*Server).Start
        /opt/boxen/homebrew/Cellar/go/1.2/libexec/src/pkg/net/http/httptest/server.go:109 +0x23b
FAIL    github.com/jingweno/go-octokit/octokit  0.023s

Looks like hypermedia.HyperFiledRelations should only be called for individual hyper resource instead of being called for the passed in interface. But I would like to confirm with you first.

owenthereal commented 10 years ago

@technoweenie I need some help from you to get this going. The main problem I have is HyperFieldRelations is called on any passed in interface, including a slice type, e.g., []Authorizations. This causes t.NumField() to fail for non-struct type. Any idea on how to fix it?

technoweenie commented 10 years ago

You're passing in a slice because the API request returns an array, correct? That's a really good point :) Definitely a bug fix for sawyer.

owenthereal commented 10 years ago

@technoweenie That's right. Some results expect an array

technoweenie commented 10 years ago

Thought about this some more and put some thoughts down here: lostisland/go-sawyer#15.

owenthereal commented 10 years ago

Closing this due to https://github.com/lostisland/go-sawyer/pull/14. Will reopen another one to incorporate https://github.com/lostisland/go-sawyer/pull/12