From 51cbc24bbecfecbbcea9cd733ad44eaf74b8ae4b Mon Sep 17 00:00:00 2001 From: Kostya Ostrovsky Date: Tue, 1 Dec 2020 11:52:53 +0200 Subject: config: support insteadOf for remotes' URLs (#79) --- config/url_test.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 config/url_test.go (limited to 'config/url_test.go') diff --git a/config/url_test.go b/config/url_test.go new file mode 100644 index 0000000..5afc9f3 --- /dev/null +++ b/config/url_test.go @@ -0,0 +1,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") +} -- cgit