summaryrefslogtreecommitdiff
path: root/refspec_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'refspec_test.go')
-rw-r--r--refspec_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/refspec_test.go b/refspec_test.go
new file mode 100644
index 0000000..7064198
--- /dev/null
+++ b/refspec_test.go
@@ -0,0 +1,75 @@
+package git
+
+import (
+ "testing"
+)
+
+func TestRefspec(t *testing.T) {
+ t.Parallel()
+
+ const (
+ input = "+refs/heads/*:refs/remotes/origin/*"
+ mainLocal = "refs/heads/main"
+ mainRemote = "refs/remotes/origin/main"
+ )
+
+ refspec, err := ParseRefspec(input, true)
+ checkFatal(t, err)
+
+ // Accessors
+
+ s := refspec.String()
+ if s != input {
+ t.Errorf("expected string %q, got %q", input, s)
+ }
+
+ if d := refspec.Direction(); d != ConnectDirectionFetch {
+ t.Errorf("expected fetch refspec, got direction %v", d)
+ }
+
+ if pat, expected := refspec.Src(), "refs/heads/*"; pat != expected {
+ t.Errorf("expected refspec src %q, got %q", expected, pat)
+ }
+
+ if pat, expected := refspec.Dst(), "refs/remotes/origin/*"; pat != expected {
+ t.Errorf("expected refspec dst %q, got %q", expected, pat)
+ }
+
+ if !refspec.Force() {
+ t.Error("expected refspec force flag")
+ }
+
+ // SrcMatches
+
+ if !refspec.SrcMatches(mainLocal) {
+ t.Errorf("refspec source did not match %q", mainLocal)
+ }
+
+ if refspec.SrcMatches("refs/tags/v1.0") {
+ t.Error("refspec source matched under refs/tags")
+ }
+
+ // DstMatches
+
+ if !refspec.DstMatches(mainRemote) {
+ t.Errorf("refspec destination did not match %q", mainRemote)
+ }
+
+ if refspec.DstMatches("refs/tags/v1.0") {
+ t.Error("refspec destination matched under refs/tags")
+ }
+
+ // Transforms
+
+ fromLocal, err := refspec.Transform(mainLocal)
+ checkFatal(t, err)
+ if fromLocal != mainRemote {
+ t.Errorf("transform by refspec returned %s; expected %s", fromLocal, mainRemote)
+ }
+
+ fromRemote, err := refspec.Rtransform(mainRemote)
+ checkFatal(t, err)
+ if fromRemote != mainLocal {
+ t.Errorf("rtransform by refspec returned %s; expected %s", fromRemote, mainLocal)
+ }
+}