-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
208 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Fuzzing | ||
on: [push, pull_request] | ||
jobs: | ||
build: | ||
name: Fuzzing | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: "go.mod" | ||
|
||
- name: Fuzz | ||
run: go test ./tests -fuzz . -fuzztime=2m |
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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/lindell/multi-gitter/cmd" | ||
"github.com/lindell/multi-gitter/tests/vcmock" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func FuzzRun(f *testing.F) { | ||
f.Add( | ||
"assignee1,assignee2", // assignees | ||
"commit message", // commit-message | ||
1, // concurrent | ||
"skip", // conflict-strategy | ||
false, // draft | ||
false, // dry-run | ||
1, // fetch-depth | ||
false, // fork | ||
"fork-owner", // fork-owner | ||
"go", // git-type | ||
"label1,label2", // labels | ||
"text", // log-format | ||
"info", // log-level | ||
1, // max-reviewers | ||
1, // max-team-reviewers | ||
"pr-body", // pr-body | ||
"pr-title", // pr-title | ||
"reviewer1,reviewer2", // reviewers | ||
false, // skip-forks | ||
false, // skip-pr | ||
"should-not-change", // skip-repo | ||
"team-reviewer1,team-reviewer1", // team-reviewers | ||
"topic1,topic2", // topic | ||
) | ||
f.Fuzz(func( | ||
t *testing.T, | ||
|
||
assignees string, | ||
commitMessage string, | ||
concurrent int, | ||
conflictStrategy string, | ||
draft bool, | ||
dryRun bool, | ||
fetchDepth int, | ||
fork bool, | ||
forkOwner string, | ||
gitType string, | ||
labels string, | ||
logFormat string, | ||
logLevel string, | ||
maxReviewers int, | ||
maxTeamReviewers int, | ||
prBody string, | ||
prTitle string, | ||
reviewers string, | ||
skipForks bool, | ||
skipPr bool, | ||
skipRepo string, | ||
teamReviewers string, | ||
topic string, | ||
) { | ||
vcMock := &vcmock.VersionController{} | ||
defer vcMock.Clean() | ||
cmd.OverrideVersionController = vcMock | ||
|
||
tmpDir, err := os.MkdirTemp(os.TempDir(), "multi-git-test-run-") | ||
defer os.RemoveAll(tmpDir) | ||
assert.NoError(t, err) | ||
|
||
workingDir, err := os.Getwd() | ||
assert.NoError(t, err) | ||
|
||
changerBinaryPath := normalizePath(filepath.Join(workingDir, changerBinaryPath)) | ||
|
||
changeRepo := createRepo(t, "owner", "should-change", "i like apples") | ||
changeRepo2 := createRepo(t, "owner", "should-change-2", "i like my apple") | ||
noChangeRepo := createRepo(t, "owner", "should-not-change", "i like oranges") | ||
vcMock.AddRepository(changeRepo) | ||
vcMock.AddRepository(changeRepo2) | ||
vcMock.AddRepository(noChangeRepo) | ||
|
||
runOutFile := filepath.Join(tmpDir, "run-out.txt") | ||
runLogFile := filepath.Join(tmpDir, "run-log.txt") | ||
|
||
command := cmd.RootCmd() | ||
command.SetArgs([]string{"run", | ||
"--output", runOutFile, | ||
"--log-file", runLogFile, | ||
"--author-name", "Test Author", | ||
"--author-email", "test@example.com", | ||
"--assignees", assignees, | ||
"--commit-message", commitMessage, | ||
"--concurrent", fmt.Sprint(concurrent), | ||
"--conflict-strategy", conflictStrategy, | ||
fmt.Sprintf("--draft=%t", draft), | ||
fmt.Sprintf("--dry-run=%t", dryRun), | ||
"--fetch-depth", fmt.Sprint(fetchDepth), | ||
fmt.Sprintf("--fork=%t", fork), | ||
"--fork-owner", forkOwner, | ||
"--git-type", gitType, | ||
"--labels", labels, | ||
"--log-format", logFormat, | ||
"--log-level", logLevel, | ||
"--max-reviewers", fmt.Sprint(maxReviewers), | ||
"--max-team-reviewers", fmt.Sprint(maxTeamReviewers), | ||
"--pr-body", prBody, | ||
"--pr-title", prTitle, | ||
"--reviewers", reviewers, | ||
fmt.Sprintf("--skip-forks=%t", skipForks), | ||
fmt.Sprintf("--skip-pr=%t", skipPr), | ||
"--skip-repo", skipRepo, | ||
"--team-reviewers", teamReviewers, | ||
"--topic", topic, | ||
changerBinaryPath, | ||
}) | ||
err = command.Execute() | ||
if err != nil { | ||
assert.NotContains(t, err.Error(), "panic") | ||
} | ||
|
||
// Verify that the output was correct | ||
runOutData, _ := os.ReadFile(runOutFile) | ||
assert.NotContains(t, string(runOutData), "panic") | ||
runLogData, _ := os.ReadFile(runLogFile) | ||
assert.NotContains(t, string(runLogData), "panic") | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
go test fuzz v1 | ||
string("0") | ||
string("0") | ||
int(69) | ||
string("skip") | ||
bool(false) | ||
bool(false) | ||
int(1) | ||
bool(true) | ||
string("0") | ||
string("go") | ||
string("0") | ||
string("text") | ||
string("info") | ||
int(1) | ||
int(-51) | ||
string("0") | ||
string("0") | ||
string("0") | ||
bool(false) | ||
bool(false) | ||
string("0") | ||
string("0") | ||
string("0") |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
go test fuzz v1 | ||
string("0") | ||
string("0") | ||
int(1) | ||
string("0") | ||
bool(false) | ||
bool(false) | ||
int(1) | ||
bool(false) | ||
string("0") | ||
string("0") | ||
string("0") | ||
string("0") | ||
string("0") | ||
int(1) | ||
int(1) | ||
string("0") | ||
string("0") | ||
string("0") | ||
bool(false) | ||
bool(false) | ||
string("0") | ||
string("0") | ||
string("0") |