{"action":"created","issue":{"url":"https://api.github.com/repos/UniversityRadioYork/myradio-go/issues/22","repository_url":"https://api.github.com/repos/UniversityRadioYork/myradio-go","labels_url":"https://api.github.com/repos/UniversityRadioYork/myradio-go/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/UniversityRadioYork/myradio-go/issues/22/comments","events_url":"https://api.github.com/repos/UniversityRadioYork/myradio-go/issues/22/events","html_url":"https://github.com/UniversityRadioYork/myradio-go/pull/22","id":184717883,"number":22,"title":"Make myradio-go more mockable","user":{"login":"CaptainHayashi","id":374963,"avatar_url":"https://avatars.githubusercontent.com/u/374963?v=3","gravatar_id":"","url":"https://api.github.com/users/CaptainHayashi","html_url":"https://github.com/CaptainHayashi","followers_url":"https://api.github.com/users/CaptainHayashi/followers","following_url":"https://api.github.com/users/CaptainHayashi/following{/other_user}","gists_url":"https://api.github.com/users/CaptainHayashi/gists{/gist_id}","starred_url":"https://api.github.com/users/CaptainHayashi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaptainHayashi/subscriptions","organizations_url":"https://api.github.com/users/CaptainHayashi/orgs","repos_url":"https://api.github.com/users/CaptainHayashi/repos","events_url":"https://api.github.com/users/CaptainHayashi/events{/privacy}","received_events_url":"https://api.github.com/users/CaptainHayashi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-23T21:43:32Z","updated_at":"2016-10-23T22:38:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/UniversityRadioYork/myradio-go/pulls/22","html_url":"https://github.com/UniversityRadioYork/myradio-go/pull/22","diff_url":"https://github.com/UniversityRadioYork/myradio-go/pull/22.diff","patch_url":"https://github.com/UniversityRadioYork/myradio-go/pull/22.patch"},"body":"This PRQ:\r\n\r\n- Splits `Session` into two things, a `Session` object that handles API requests from clients, and an `apiRequester` interface that actually does the API request;\r\n- Moves the old `Session` behaviour into `authedRequester` (which implements `apiRequester`);\r\n- Adds a new `mockRequester` that pretends to do an API request but instead returns a stock `json.RawMessage`;\r\n- Allows `Session`s to be created with `mockRequesters` using the new `MockSession` constructor;\r\n- Adds a (rather pointless) test to show how this can be used.\r\n\r\nThus, any of myradio-go's existing methods can now be sent a JSON file directly instead of having to make an API call, which makes testing the myradio-go specific logic much easier!\r\n\r\nThis might seem a little overengineered, but it's the easiest way I could think of to make this possible.\r\n\r\nThe reason `Session` still exists, instead of using `apiRequester` directly, is backwards compatibility; allowing the myradio-go API to remain method-based; allowing helper methods like `apiRequest` to be defined without changing the requesters; and allowing future expansion of what lives in `Session`.\r\n\r\nThings that would be nice:\r\n- Move `show_test`'s JSON into a separate file;\r\n- Make it so myradio-go can dump out the JSON from calling an API method, so that it can be used for future testing.  This might be better done in an external shell script wrapping `curl` though."},"comment":{"url":"https://api.github.com/repos/UniversityRadioYork/myradio-go/issues/comments/255619754","html_url":"https://github.com/UniversityRadioYork/myradio-go/pull/22#issuecomment-255619754","issue_url":"https://api.github.com/repos/UniversityRadioYork/myradio-go/issues/22","id":255619754,"user":{"login":"CaptainHayashi","id":374963,"avatar_url":"https://avatars.githubusercontent.com/u/374963?v=3","gravatar_id":"","url":"https://api.github.com/users/CaptainHayashi","html_url":"https://github.com/CaptainHayashi","followers_url":"https://api.github.com/users/CaptainHayashi/followers","following_url":"https://api.github.com/users/CaptainHayashi/following{/other_user}","gists_url":"https://api.github.com/users/CaptainHayashi/gists{/gist_id}","starred_url":"https://api.github.com/users/CaptainHayashi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaptainHayashi/subscriptions","organizations_url":"https://api.github.com/users/CaptainHayashi/orgs","repos_url":"https://api.github.com/users/CaptainHayashi/repos","events_url":"https://api.github.com/users/CaptainHayashi/events{/privacy}","received_events_url":"https://api.github.com/users/CaptainHayashi/received_events","type":"User","site_admin":false},"created_at":"2016-10-23T22:38:52Z","updated_at":"2016-10-23T22:38:52Z","body":"@LordAro short of having the myradio-go tests spin up an entire implementation of the MyRadio API, I'm not sure how these tests can do anything other than just checking the interpretation of JSON.  (Some API methods do more than just unmarshal the JSON, the test here was just a quick proof of context).\r\n\r\nI'd argue that even making sure the JSON marshalling works can be useful.  First, until I did the lint branch the track marshalling was completely broken and nobody noticed.  Second, it ensures that if we change `GetSearchMeta` or the `ShowMeta` struct there's a bit of code exercising it (that isn't an external client) that'll break enough to make us sure we've covered all our bases.\r\n\r\nIf anyone can find a way of making it less verbose, then sure.  I picked a bad example in hindsight: show metadata is inherently very verbose!"}}
{"actor":{"display_login":"CaptainHayashi"}}