Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move reader functions for coverage test.
Move GetReadWriter and GetReadCloser from apps.go to apps_test.go to improve coverage.
  • Loading branch information
emoryruscus authored Aug 8, 2019
commit d0693320a7664a89fd1291a5a12f2b9eb054bd51
28 changes: 28 additions & 0 deletions github/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,31 @@ func TestAppsService_FindUserInstallation(t *testing.T) {
t.Errorf("Apps.FindUserInstallation returned %+v, want %+v", installation, want)
}
}

// GetReadWriter converts a body interface into an io.ReadWriter object.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I much prefer these two new helper functions be used for testing only... thank you!

In fact, since they are rather general purpose, I would be fine to move them to github_test.go if you want, or we could just leave them here for now and move them in a later PR if they become more generally used.

We'll see what @gauntface thinks about them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome! Will leave them here for now if that is alright.

func GetReadWriter(body interface{}) (io.ReadWriter, error) {
var buf io.ReadWriter
if body != nil {
buf = new(bytes.Buffer)
enc := json.NewEncoder(buf)
err := enc.Encode(body)
if err != nil {
return nil, err
}
}
return buf, nil
}

// GetReadCloser converts a body interface into an io.ReadCloser object.
func GetReadCloser(body interface{}) (io.ReadCloser, error) {
buf, err := GetReadWriter(body)
if err != nil {
return nil, err
}

all, err := ioutil.ReadAll(buf)
if err != nil {
return nil, err
}
return ioutil.NopCloser(bytes.NewBuffer(all)), nil
}