| /* |
| Copyright 2013 Google Inc. All Rights Reserved. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| */ |
| |
| package gerrit_test |
| |
| import ( |
| "fmt" |
| "strings" |
| "testing" |
| |
| "gwt.googlesource.com/buildglue.git/gerrit" |
| ) |
| |
| func TestParseRefs(t *testing.T) { |
| // Revelant snippet from https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#current-revision |
| input := `)]}' |
| [ |
| { |
| "current_revision": "184ebe53805e102605d11f6b143486d15c23a09c", |
| "revisions": { |
| "184ebe53805e102605d11f6b143486d15c23a09c": { |
| "fetch": { |
| "http": { |
| "ref": "refs/changes/97/97/1" |
| } |
| } |
| } |
| } |
| }, |
| { |
| "current_revision": "27cc4558b5a3d3387dd11ee2df7a117e7e581822", |
| "revisions": { |
| "27cc4558b5a3d3387dd11ee2df7a117e7e581822": { |
| "fetch": { |
| "http": { |
| "ref": "refs/changes/99/4799/2" |
| } |
| } |
| } |
| } |
| } |
| ] |
| ` |
| expect := []string{"refs/changes/97/97/1", "refs/changes/99/4799/2"} |
| |
| actual, err := gerrit.ParseRefs(strings.NewReader(input)) |
| if err != nil { |
| t.Error("failed to parse input:", err) |
| } |
| if fmt.Sprintf("%#v", expect) != fmt.Sprintf("%#v", actual) { |
| t.Errorf("expect %#v, actual %#v", expect, actual) |
| } |
| } |