-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from tab/feature/interactive-edit
feat(commit): Interactive commit message editing
- Loading branch information
Showing
13 changed files
with
307 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os" | ||
"testing" | ||
"bytes" | ||
"io" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMainRun(t *testing.T) { | ||
origArgs := os.Args | ||
defer func() { os.Args = origArgs }() | ||
|
||
tests := []struct { | ||
name string | ||
args []string | ||
output string | ||
}{ | ||
{ | ||
name: "Help command", | ||
args: []string{"--help"}, | ||
output: "Usage:", | ||
}, | ||
{ | ||
name: "Version command", | ||
args: []string{"--version"}, | ||
output: "cmt 0.3.0\n", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
os.Args = append([]string{"cmd"}, tt.args...) | ||
|
||
r, w, _ := os.Pipe() | ||
origStdout := os.Stdout | ||
os.Stdout = w | ||
defer func() { os.Stdout = origStdout }() | ||
|
||
main() | ||
|
||
w.Close() | ||
var buf bytes.Buffer | ||
_, err := io.Copy(&buf, r) | ||
if err != nil { | ||
return | ||
} | ||
result := buf.String() | ||
|
||
assert.Contains(t, result, tt.output) | ||
}) | ||
} | ||
origArgs := os.Args | ||
defer func() { os.Args = origArgs }() | ||
|
||
tests := []struct { | ||
name string | ||
args []string | ||
output string | ||
}{ | ||
{ | ||
name: "Help command", | ||
args: []string{"--help"}, | ||
output: "Usage:", | ||
}, | ||
{ | ||
name: "Version command", | ||
args: []string{"--version"}, | ||
output: "cmt 0.3.0\n", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
os.Args = append([]string{"cmd"}, tt.args...) | ||
|
||
r, w, _ := os.Pipe() | ||
origStdout := os.Stdout | ||
os.Stdout = w | ||
defer func() { os.Stdout = origStdout }() | ||
|
||
main() | ||
|
||
w.Close() | ||
var buf bytes.Buffer | ||
_, err := io.Copy(&buf, r) | ||
if err != nil { | ||
return | ||
} | ||
result := buf.String() | ||
|
||
assert.Contains(t, result, tt.output) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,93 @@ | ||
package changelog | ||
|
||
import ( | ||
"bytes" | ||
"cmt/internal/commands" | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
"testing" | ||
"bytes" | ||
"cmt/internal/commands" | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/mock/gomock" | ||
|
||
"cmt/internal/git" | ||
"cmt/internal/gpt" | ||
"cmt/internal/git" | ||
"cmt/internal/gpt" | ||
) | ||
|
||
func Test_Generate(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockGitClient := git.NewMockGitClient(ctrl) | ||
mockGPTModelClient := gpt.NewMockGPTModelClient(ctrl) | ||
ctx := context.Background() | ||
|
||
mockGitClient := git.NewMockGitClient(ctrl) | ||
mockGPTModelClient := gpt.NewMockGPTModelClient(ctrl) | ||
ctx := context.Background() | ||
options := commands.GenerateOptions{ | ||
Ctx: ctx, | ||
Client: mockGitClient, | ||
Model: mockGPTModelClient, | ||
} | ||
|
||
options := commands.GenerateOptions{ | ||
Ctx: ctx, | ||
Client: mockGitClient, | ||
Model: mockGPTModelClient, | ||
} | ||
type result struct { | ||
output string | ||
err bool | ||
} | ||
|
||
type result struct { | ||
output string | ||
err bool | ||
} | ||
tests := []struct { | ||
name string | ||
before func() | ||
expected result | ||
}{ | ||
{ | ||
name: "Success", | ||
before: func() { | ||
mockGitClient.EXPECT().Log(ctx, nil).Return("mock log output", nil) | ||
mockGPTModelClient.EXPECT().FetchChangelog(ctx, "mock log output").Return("# CHANGELOG", nil) | ||
}, | ||
expected: result{ | ||
output: "💬 Changelog: \n\n# CHANGELOG", | ||
err: false, | ||
}, | ||
}, | ||
{ | ||
name: "Error fetching log", | ||
before: func() { | ||
mockGitClient.EXPECT().Log(ctx, nil).Return("", fmt.Errorf("git log error")) | ||
}, | ||
expected: result{ | ||
output: "", | ||
err: true, | ||
}, | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
before func() | ||
expected result | ||
}{ | ||
{ | ||
name: "Success", | ||
before: func() { | ||
mockGitClient.EXPECT().Log(ctx, nil).Return("mock log output", nil) | ||
mockGPTModelClient.EXPECT().FetchChangelog(ctx, "mock log output").Return("# CHANGELOG", nil) | ||
}, | ||
expected: result{ | ||
output: "💬 Changelog: \n\n# CHANGELOG", | ||
err: false, | ||
}, | ||
}, | ||
{ | ||
name: "Error fetching log", | ||
before: func() { | ||
mockGitClient.EXPECT().Log(ctx, nil).Return("", fmt.Errorf("git log error")) | ||
}, | ||
expected: result{ | ||
output: "", | ||
err: true, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.before() | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.before() | ||
r, w, _ := os.Pipe() | ||
defer r.Close() | ||
defer w.Close() | ||
origStdout := os.Stdout | ||
os.Stdout = w | ||
defer func() { os.Stdout = origStdout }() | ||
|
||
r, w, _ := os.Pipe() | ||
defer r.Close() | ||
defer w.Close() | ||
origStdout := os.Stdout | ||
os.Stdout = w | ||
defer func() { os.Stdout = origStdout }() | ||
err := NewCommand(options).Generate() | ||
|
||
err := NewCommand(options).Generate() | ||
w.Close() | ||
var buf bytes.Buffer | ||
_, _ = io.Copy(&buf, r) | ||
output := buf.String() | ||
|
||
w.Close() | ||
var buf bytes.Buffer | ||
_, _ = io.Copy(&buf, r) | ||
output := buf.String() | ||
if tt.expected.err { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
|
||
if tt.expected.err { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
|
||
assert.Contains(t, output, tt.expected.output) | ||
}) | ||
} | ||
assert.Contains(t, output, tt.expected.output) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.