| 1 |
package config |
| 2 |
|
| 3 |
import ( |
| 4 |
. "gopkg.in/check.v1" |
| 5 |
) |
| 6 |
|
| 7 |
type URLSuite struct{} |
| 8 |
|
| 9 |
var _ = Suite(&URLSuite{}) |
| 10 |
|
| 11 |
func (b *URLSuite) TestValidateInsteadOf(c *C) { |
| 12 |
goodURL := URL{ |
| 13 |
Name: "ssh://github.com", |
| 14 |
InsteadOf: "http://github.com", |
| 15 |
} |
| 16 |
badURL := URL{} |
| 17 |
c.Assert(goodURL.Validate(), IsNil) |
| 18 |
c.Assert(badURL.Validate(), NotNil) |
| 19 |
} |
| 20 |
|
| 21 |
func (b *URLSuite) TestMarshal(c *C) { |
| 22 |
expected := []byte(`[core] |
| 23 |
bare = false |
| 24 |
[url "ssh://[email protected]/"] |
| 25 |
insteadOf = https://github.com/ |
| 26 |
`) |
| 27 |
|
| 28 |
cfg := NewConfig() |
| 29 |
cfg.URLs["ssh://[email protected]/"] = &URL{ |
| 30 |
Name: "ssh://[email protected]/", |
| 31 |
InsteadOf: "https://github.com/", |
| 32 |
} |
| 33 |
|
| 34 |
actual, err := cfg.Marshal() |
| 35 |
c.Assert(err, IsNil) |
| 36 |
c.Assert(string(actual), Equals, string(expected)) |
| 37 |
} |
| 38 |
|
| 39 |
func (b *URLSuite) TestUnmarshal(c *C) { |
| 40 |
input := []byte(`[core] |
| 41 |
bare = false |
| 42 |
[url "ssh://[email protected]/"] |
| 43 |
insteadOf = https://github.com/ |
| 44 |
`) |
| 45 |
|
| 46 |
cfg := NewConfig() |
| 47 |
err := cfg.Unmarshal(input) |
| 48 |
c.Assert(err, IsNil) |
| 49 |
url := cfg.URLs["ssh://[email protected]/"] |
| 50 |
c.Assert(url.Name, Equals, "ssh://[email protected]/") |
| 51 |
c.Assert(url.InsteadOf, Equals, "https://github.com/") |
| 52 |
} |
| 53 |
|
| 54 |
func (b *URLSuite) TestApplyInsteadOf(c *C) { |
| 55 |
urlRule := URL{ |
| 56 |
Name: "ssh://github.com", |
| 57 |
InsteadOf: "http://github.com", |
| 58 |
} |
| 59 |
|
| 60 |
c.Assert(urlRule.ApplyInsteadOf("http://google.com"), Equals, "http://google.com") |
| 61 |
c.Assert(urlRule.ApplyInsteadOf("http://github.com/myrepo"), Equals, "ssh://github.com/myrepo") |
| 62 |
} |