Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1919)

Delta Between Two Patch Sets: src/cmd/goinstall/download_test.go

Issue 5343042: code review 5343042: goinstall: support googlecode subrepos and add repo mat... (Closed)
Left Patch Set: diff -r 9526029204c3 https://go.googlecode.com/hg/ Created 13 years, 4 months ago
Right Patch Set: diff -r 4bec71996c9f https://go.googlecode.com/hg/ Created 13 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/goinstall/download.go ('k') | src/cmd/goinstall/main.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "errors" 9 "errors"
10 "http"
11 "io/ioutil" 10 "io/ioutil"
11 "net/http"
12 "testing" 12 "testing"
13 ) 13 )
14 14
15 var FindPublicRepoTests = []struct { 15 var FindPublicRepoTests = []struct {
16 » pkg string 16 » pkg string
17 » vcs, prefix, repo string 17 » vcs, root, url string
18 » transport *testTransport 18 » transport *testTransport
19 }{ 19 }{
20 { 20 {
21 "repo.googlecode.com/hg/path/foo", 21 "repo.googlecode.com/hg/path/foo",
22 "hg", 22 "hg",
23 "repo.googlecode.com/hg", 23 "repo.googlecode.com/hg",
24 "https://repo.googlecode.com/hg", 24 "https://repo.googlecode.com/hg",
25 nil, 25 nil,
26 }, 26 },
27 { 27 {
28 "repo.googlecode.com/svn/path", 28 "repo.googlecode.com/svn/path",
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 nil, 90 nil,
91 }, 91 },
92 } 92 }
93 93
94 func TestFindPublicRepo(t *testing.T) { 94 func TestFindPublicRepo(t *testing.T) {
95 for _, test := range FindPublicRepoTests { 95 for _, test := range FindPublicRepoTests {
96 client := http.DefaultClient 96 client := http.DefaultClient
97 if test.transport != nil { 97 if test.transport != nil {
98 client = &http.Client{Transport: test.transport} 98 client = &http.Client{Transport: test.transport}
99 } 99 }
100 » » m, err := findPublicRepo(test.pkg, client) 100 » » repo, err := findPublicRepo(test.pkg)
101 if err != nil { 101 if err != nil {
102 » » » t.Errorf("%s: got error: %v", test.pkg, err) 102 » » » t.Errorf("findPublicRepo(%s): error: %v", test.pkg, err)
103 continue 103 continue
104 } 104 }
105 » » if m == nil { 105 » » if repo == nil {
106 t.Errorf("%s: got nil match", test.pkg) 106 t.Errorf("%s: got nil match", test.pkg)
107 continue 107 continue
108 } 108 }
109 109 » » url, root, vcs, err := repo.Repo(client)
110 » » if v := vcsMap[test.vcs]; m.vcs != v { 110 » » if err != nil {
111 » » » t.Errorf("%s: got vcs=%v, want %v", test.pkg, m.vcs, v) 111 » » » t.Errorf("%s: repo.Repo error: %v", test.pkg, err)
112 » » » continue
112 } 113 }
113 » » if m.prefix != test.prefix { 114 » » if v := vcsMap[test.vcs]; vcs != v {
114 » » » t.Errorf("%s: got prefix=%v, want %v", test.pkg, m.prefi x, test.prefix) 115 » » » t.Errorf("%s: got vcs=%v, want %v", test.pkg, vcs, v)
115 } 116 }
116 » » if m.repo != test.repo { 117 » » if root != test.root {
117 » » » t.Errorf("%s: got repo=%v, want %v", test.pkg, m.repo, t est.repo) 118 » » » t.Errorf("%s: got root=%v, want %v", test.pkg, root, tes t.root)
119 » » }
120 » » if url != test.url {
121 » » » t.Errorf("%s: got url=%v, want %v", test.pkg, url, test. url)
118 } 122 }
119 } 123 }
120 } 124 }
121 125
122 type testTransport struct { 126 type testTransport struct {
123 expectURL string 127 expectURL string
124 responseBody string 128 responseBody string
125 } 129 }
126 130
127 func (t *testTransport) RoundTrip(req *http.Request) (*http.Response, error) { 131 func (t *testTransport) RoundTrip(req *http.Request) (*http.Response, error) {
128 if g, e := req.URL.String(), t.expectURL; g != e { 132 if g, e := req.URL.String(), t.expectURL; g != e {
129 return nil, errors.New("want " + e) 133 return nil, errors.New("want " + e)
130 } 134 }
131 body := ioutil.NopCloser(bytes.NewBufferString(t.responseBody)) 135 body := ioutil.NopCloser(bytes.NewBufferString(t.responseBody))
132 return &http.Response{ 136 return &http.Response{
133 StatusCode: http.StatusOK, 137 StatusCode: http.StatusOK,
134 Body: body, 138 Body: body,
135 }, nil 139 }, nil
136 } 140 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b