diff options
| author | mo khan <mo@mokhan.ca> | 2026-01-30 17:18:31 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2026-01-30 17:18:31 -0700 |
| commit | e4ed0342932b0aa741ee78d9e4fe135eba6e9ca7 (patch) | |
| tree | f1e7f602cb86e78aedf04185b2c2e1428fc5b8f2 /pkg/git | |
| parent | 83be9ddcf82e8a90ea50a9d54c1ebfc3e22ace16 (diff) | |
initial commit
Diffstat (limited to 'pkg/git')
| -rw-r--r-- | pkg/git/git_test.go | 64 | ||||
| -rw-r--r-- | pkg/git/utils_test.go | 80 |
2 files changed, 0 insertions, 144 deletions
diff --git a/pkg/git/git_test.go b/pkg/git/git_test.go deleted file mode 100644 index 7ec0eb1..0000000 --- a/pkg/git/git_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package git - -import ( - "testing" -) - -func TestParseRefNames_Empty(t *testing.T) { - got := parseRefNames("") - if len(got) != 0 { - t.Fatalf("expected empty slice, got %v", got) - } -} - -func TestParseRefNames_Mixed(t *testing.T) { - input := "HEAD -> main, tag: v1.0.0, origin/HEAD -> origin/main, origin/main, master" - got := parseRefNames(input) - if len(got) != 5 { - t.Fatalf("expected 5 entries, got %d (%v)", len(got), got) - } - - // 1: HEAD pointer - if got[0].Kind != RefKindHEAD || got[0].Name != "HEAD" || got[0].Target != "main" { - t.Errorf("unexpected HEAD entry: %+v", got[0]) - } - // 2: tag - if got[1].Kind != RefKindTag || got[1].Name != "v1.0.0" || got[1].Target != "" { - t.Errorf("unexpected Tag entry: %+v", got[1]) - } - // 3: remote HEAD pointer - if got[2].Kind != RefKindRemoteHEAD || got[2].Name != "origin/HEAD" || got[2].Target != "origin/main" { - t.Errorf("unexpected RemoteHEAD entry: %+v", got[2]) - } - // 4: remote branch - if got[3].Kind != RefKindRemote || got[3].Name != "origin/main" || got[3].Target != "" { - t.Errorf("unexpected Remote entry: %+v", got[3]) - } - // 5: local branch - if got[4].Kind != RefKindBranch || got[4].Name != "master" || got[4].Target != "" { - t.Errorf("unexpected Branch entry: %+v", got[4]) - } -} - -func TestParseRefNames_Singles(t *testing.T) { - cases := []struct { - in string - kind RefKind - name string - target string - }{ - {"tag: v2", RefKindTag, "v2", ""}, - {"main", RefKindBranch, "main", ""}, - {"origin/dev", RefKindRemote, "origin/dev", ""}, - {"origin/HEAD -> origin/main", RefKindRemoteHEAD, "origin/HEAD", "origin/main"}, - } - for _, c := range cases { - got := parseRefNames(c.in) - if len(got) != 1 { - t.Fatalf("%q: expected 1 entry, got %d (%v)", c.in, len(got), got) - } - if got[0].Kind != c.kind || got[0].Name != c.name || got[0].Target != c.target { - t.Errorf("%q: unexpected entry: %+v", c.in, got[0]) - } - } -} diff --git a/pkg/git/utils_test.go b/pkg/git/utils_test.go deleted file mode 100644 index 4dcebe8..0000000 --- a/pkg/git/utils_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package git_test - -import ( - "strings" - "testing" - - "github.com/antonmedv/gitmal/pkg/git" -) - -func TestParseFileMode(t *testing.T) { - tests := []struct { - mode string - expected string - }{ - {"100644", "rw-r--r--"}, - {"100755", "rwxr-xr-x"}, - {"100600", "rw-------"}, - {"100400", "r--------"}, - } - - for _, tt := range tests { - t.Run(tt.mode, func(t *testing.T) { - result, err := git.ParseFileMode(tt.mode) - if err != nil { - t.Errorf("unexpected error: %v", err) - } - if result != tt.expected { - t.Errorf("got %q, want %q", result, tt.expected) - } - }) - } -} - -func TestParseFileModeInvalid(t *testing.T) { - tests := []string{ - "", - "12", - "abc", - "10070x", - } - - for _, mode := range tests { - t.Run(mode, func(t *testing.T) { - result, err := git.ParseFileMode(mode) - if err == nil { - t.Error("expected error, got nil") - } - if result != "" { - t.Errorf("expected empty result, got %q", result) - } - if !strings.Contains(err.Error(), "invalid mode") && !strings.Contains(err.Error(), "strconv.Atoi") { - t.Errorf("unexpected error message: %v", err) - } - }) - } -} - -func TestRefToFileName(t *testing.T) { - tests := []struct { - in string - want string - }{ - {"main", "main"}, - {"master", "master"}, - {"release/v1.0", "release-v1.0"}, - {"feature/add-login", "feature-add-login"}, - {"bugfix\\windows\\path", "bugfix-windows-path"}, - {"1.0.0", "1.0.0"}, - {"1.x", "1.x"}, - } - - for _, tt := range tests { - t.Run(tt.in, func(t *testing.T) { - got := git.RefToFileName(tt.in) - if got != tt.want { - t.Fatalf("refToFileName(%q) = %q, want %q", tt.in, got, tt.want) - } - }) - } -} |
