-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FilesOptions to ListFiles, ListFilesReviewed.
Modify ListFilesReviewed to return a slice of strings, rather than slice of FileInfos. This matches its actual behavior. Modify both ListFiles and ListFilesReviewed to return map/slice directly, rather than a pointer to one. There doesn't appear to be any value in returning a pointer, it just makes the API harder to use. Slice/map are already reference types. Modify all endpoints to escape fileID parameter so it can be safely placed inside a URL path segment. Make note of Base parameter being undocumented for ListFiles endpoints. However, it has been tested and it works (it's a very important parameter to support). Add tests for ListFiles, ListFilesReviewed.
- Loading branch information
1 parent
5ff0cbc
commit 2e8da2e
Showing
2 changed files
with
137 additions
and
22 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package gerrit_test | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/andygrunwald/go-gerrit" | ||
) | ||
|
||
func TestChangesService_ListFiles(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if got, want := r.URL.String(), "/changes/123/revisions/456/files/?base=7"; got != want { | ||
t.Errorf("request URL:\ngot: %q\nwant: %q", got, want) | ||
} | ||
fmt.Fprint(w, `{ | ||
"/COMMIT_MSG": { | ||
"status": "A", | ||
"lines_inserted": 7, | ||
"size_delta": 551, | ||
"size": 551 | ||
}, | ||
"gerrit-server/RefControl.java": { | ||
"lines_inserted": 5, | ||
"lines_deleted": 3, | ||
"size_delta": 98, | ||
"size": 23348 | ||
} | ||
}`) | ||
})) | ||
defer ts.Close() | ||
|
||
client := newClient(t, ts) | ||
got, _, err := client.Changes.ListFiles("123", "456", &gerrit.FilesOptions{ | ||
Base: "7", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
want := map[string]gerrit.FileInfo{ | ||
"/COMMIT_MSG": { | ||
Status: "A", | ||
LinesInserted: 7, | ||
SizeDelta: 551, | ||
Size: 551, | ||
}, | ||
"gerrit-server/RefControl.java": { | ||
LinesInserted: 5, | ||
LinesDeleted: 3, | ||
SizeDelta: 98, | ||
Size: 23348, | ||
}, | ||
} | ||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("client.Changes.ListFiles:\ngot: %+v\nwant: %+v", got, want) | ||
} | ||
} | ||
|
||
func TestChangesService_ListFilesReviewed(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if got, want := r.URL.String(), "/changes/123/revisions/456/files/?q=abc&reviewed=true"; got != want { | ||
t.Errorf("request URL:\ngot: %q\nwant: %q", got, want) | ||
} | ||
fmt.Fprint(w, `["/COMMIT_MSG","gerrit-server/RefControl.java"]`) | ||
})) | ||
defer ts.Close() | ||
|
||
client := newClient(t, ts) | ||
got, _, err := client.Changes.ListFilesReviewed("123", "456", &gerrit.FilesOptions{ | ||
Q: "abc", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
want := []string{"/COMMIT_MSG", "gerrit-server/RefControl.java"} | ||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("client.Changes.ListFilesReviewed:\ngot: %q\nwant: %q", got, want) | ||
} | ||
} |