aboutsummaryrefslogtreecommitdiffstats
path: root/config/url_test.go
diff options
context:
space:
mode:
authorKostya Ostrovsky <kostyay@users.noreply.github.com>2020-12-01 11:52:53 +0200
committerGitHub <noreply@github.com>2020-12-01 10:52:53 +0100
commit51cbc24bbecfecbbcea9cd733ad44eaf74b8ae4b (patch)
tree73a4fdcb346d3233181781e37d1929b457a65216 /config/url_test.go
parentd525a514057f97bc2b183e2c67f542dd6f0ac0aa (diff)
downloadgo-git-51cbc24bbecfecbbcea9cd733ad44eaf74b8ae4b.tar.gz
config: support insteadOf for remotes' URLs (#79)
Diffstat (limited to 'config/url_test.go')
-rw-r--r--config/url_test.go62
1 files changed, 62 insertions, 0 deletions
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")
+}