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