MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestCheckGitVersion

Function TestCheckGitVersion

internal/gitcmd/version_test.go:88–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestCheckGitVersion(t *testing.T) {
89 t.Run("happy path", func(t *testing.T) {
90 getVersion := func() ([]byte, error) {
91 return []byte("git version 2.45.2\n"), nil
92 }
93 if err := checkGitVersion(getVersion); err != nil {
94 t.Fatalf("unexpected error: %v", err)
95 }
96 })
97
98 t.Run("old git returns typed error", func(t *testing.T) {
99 getVersion := func() ([]byte, error) {
100 return []byte("git version 2.30.0\n"), nil
101 }
102 err := checkGitVersion(getVersion)
103 var tooOld *VersionTooOldError
104 if !errors.As(err, &tooOld) {
105 t.Fatalf("expected *VersionTooOldError, got %v", err)
106 }
107 if tooOld.Current != (GitVersion{2, 30, 0}) {
108 t.Errorf("Current = %v, want 2.30.0", tooOld.Current)
109 }
110 if tooOld.Minimum != gitVersionMin {
111 t.Errorf("Minimum = %v, want %v", tooOld.Minimum, gitVersionMin)
112 }
113 })
114
115 t.Run("getVersion error", func(t *testing.T) {
116 getVersion := func() ([]byte, error) {
117 return nil, errors.New("git not found")
118 }
119 if err := checkGitVersion(getVersion); err == nil {
120 t.Fatal("expected error, got nil")
121 }
122 })
123
124 t.Run("garbage output", func(t *testing.T) {
125 getVersion := func() ([]byte, error) {
126 return []byte("banana\n"), nil
127 }
128 if err := checkGitVersion(getVersion); err == nil {
129 t.Fatal("expected parse error, got nil")
130 }
131 })
132}
133
134func TestCheckGitVersion_Real(t *testing.T) {
135 if _, err := exec.LookPath("git"); err != nil {

Callers

nothing calls this directly

Calls 2

checkGitVersionFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected