mirror of
https://github.com/hanzoai/cd.git
synced 2026-10-30 14:56:45 +00:00
Rename test names, comments, fixture data, and mock GitHub/webhook responses that still said Argo/ArgoCD/argocd/argoproj in our own voice, matching the hanzocd-* binary/configmap names and the apps.hanzo.ai CRD/annotation domain already established elsewhere in the fork. Also drop the dated argov1alpha1/argoprojiov1alpha1 import aliases for our own v1alpha1 API package. Restore the CRD groups a prior blind rename had mangled on a vendored third-party Argo Workflows example manifest back to the real argoproj.io, and fix several places where an earlier half-finished rename had gone silently wrong instead of just being cosmetic: stale CD_BINARY_NAME values and a stale --argocd-repo-server flag no longer recognized by the binary, cert filenames and an ssh_known_hosts alias that didn't match what's actually on disk, a namespace and a kustomize image substitution that were silent no-ops, and a test assertion regex that could never match its own fixture. External lookup keys we don't control are left byte-exact: quay.io/argoprojlabs images, the docker.io/argoproj CI builder image, live argoproj/argo-workflows release URLs, the generated ArgoprojV1alpha1() clientset method, and the Makefile-coupled /tmp/argo-e2e and GOPATH mount conventions.
406 lines
9.6 KiB
Go
406 lines
9.6 KiB
Go
package pull_request
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
)
|
|
|
|
func TestFilterBranchMatchBadRegexp(t *testing.T) {
|
|
t.Parallel()
|
|
provider, _ := NewFakeService(
|
|
t.Context(),
|
|
[]*PullRequest{
|
|
{
|
|
Number: 1,
|
|
Title: "PR branch1",
|
|
Branch: "branch1",
|
|
TargetBranch: "master",
|
|
HeadSHA: "089d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name1",
|
|
},
|
|
},
|
|
nil,
|
|
)
|
|
filters := []v1alpha1.PullRequestGeneratorFilter{
|
|
{
|
|
BranchMatch: new("("),
|
|
},
|
|
}
|
|
_, err := ListPullRequests(t.Context(), provider, filters)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestFilterBranchMatch(t *testing.T) {
|
|
t.Parallel()
|
|
provider, _ := NewFakeService(
|
|
t.Context(),
|
|
[]*PullRequest{
|
|
{
|
|
Number: 1,
|
|
Title: "PR one",
|
|
Branch: "one",
|
|
TargetBranch: "master",
|
|
HeadSHA: "189d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name1",
|
|
},
|
|
{
|
|
Number: 2,
|
|
Title: "PR two",
|
|
Branch: "two",
|
|
TargetBranch: "master",
|
|
HeadSHA: "289d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name2",
|
|
},
|
|
{
|
|
Number: 3,
|
|
Title: "PR three",
|
|
Branch: "three",
|
|
TargetBranch: "master",
|
|
HeadSHA: "389d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name3",
|
|
},
|
|
{
|
|
Number: 4,
|
|
Title: "PR four",
|
|
Branch: "four",
|
|
TargetBranch: "master",
|
|
HeadSHA: "489d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name4",
|
|
},
|
|
},
|
|
nil,
|
|
)
|
|
filters := []v1alpha1.PullRequestGeneratorFilter{
|
|
{
|
|
BranchMatch: new("w"),
|
|
},
|
|
}
|
|
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
|
require.NoError(t, err)
|
|
assert.Len(t, pullRequests, 1)
|
|
assert.Equal(t, "two", pullRequests[0].Branch)
|
|
}
|
|
|
|
func TestFilterTargetBranchMatch(t *testing.T) {
|
|
t.Parallel()
|
|
provider, _ := NewFakeService(
|
|
t.Context(),
|
|
[]*PullRequest{
|
|
{
|
|
Number: 1,
|
|
Title: "PR one",
|
|
Branch: "one",
|
|
TargetBranch: "master",
|
|
HeadSHA: "189d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name1",
|
|
},
|
|
{
|
|
Number: 2,
|
|
Title: "PR two",
|
|
Branch: "two",
|
|
TargetBranch: "branch1",
|
|
HeadSHA: "289d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name2",
|
|
},
|
|
{
|
|
Number: 3,
|
|
Title: "PR three",
|
|
Branch: "three",
|
|
TargetBranch: "branch2",
|
|
HeadSHA: "389d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name3",
|
|
},
|
|
{
|
|
Number: 4,
|
|
Title: "PR four",
|
|
Branch: "four",
|
|
TargetBranch: "branch3",
|
|
HeadSHA: "489d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name4",
|
|
},
|
|
},
|
|
nil,
|
|
)
|
|
filters := []v1alpha1.PullRequestGeneratorFilter{
|
|
{
|
|
TargetBranchMatch: new("1"),
|
|
},
|
|
}
|
|
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
|
require.NoError(t, err)
|
|
assert.Len(t, pullRequests, 1)
|
|
assert.Equal(t, "two", pullRequests[0].Branch)
|
|
}
|
|
|
|
func TestFilterTitleMatch(t *testing.T) {
|
|
t.Parallel()
|
|
provider, _ := NewFakeService(
|
|
t.Context(),
|
|
[]*PullRequest{
|
|
{
|
|
Number: 1,
|
|
Title: "PR one - filter",
|
|
Branch: "one",
|
|
TargetBranch: "master",
|
|
HeadSHA: "189d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name1",
|
|
},
|
|
{
|
|
Number: 2,
|
|
Title: "PR two - ignore",
|
|
Branch: "two",
|
|
TargetBranch: "branch1",
|
|
HeadSHA: "289d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name2",
|
|
},
|
|
{
|
|
Number: 3,
|
|
Title: "[filter] PR three",
|
|
Branch: "three",
|
|
TargetBranch: "branch2",
|
|
HeadSHA: "389d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name3",
|
|
},
|
|
{
|
|
Number: 4,
|
|
Title: "[ignore] PR four",
|
|
Branch: "four",
|
|
TargetBranch: "branch3",
|
|
HeadSHA: "489d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name4",
|
|
},
|
|
},
|
|
nil,
|
|
)
|
|
filters := []v1alpha1.PullRequestGeneratorFilter{
|
|
{
|
|
TitleMatch: new("\\[filter]"),
|
|
},
|
|
}
|
|
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
|
require.NoError(t, err)
|
|
assert.Len(t, pullRequests, 1)
|
|
assert.Equal(t, "three", pullRequests[0].Branch)
|
|
}
|
|
|
|
func TestMultiFilterOrWithTitle(t *testing.T) {
|
|
t.Parallel()
|
|
provider, _ := NewFakeService(
|
|
t.Context(),
|
|
[]*PullRequest{
|
|
{
|
|
Number: 1,
|
|
Title: "PR one - filter",
|
|
Branch: "one",
|
|
TargetBranch: "master",
|
|
HeadSHA: "189d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name1",
|
|
},
|
|
{
|
|
Number: 2,
|
|
Title: "PR two - ignore",
|
|
Branch: "two",
|
|
TargetBranch: "branch1",
|
|
HeadSHA: "289d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name2",
|
|
},
|
|
{
|
|
Number: 3,
|
|
Title: "[filter] PR three",
|
|
Branch: "three",
|
|
TargetBranch: "branch2",
|
|
HeadSHA: "389d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name3",
|
|
},
|
|
{
|
|
Number: 4,
|
|
Title: "[ignore] PR four",
|
|
Branch: "four",
|
|
TargetBranch: "branch3",
|
|
HeadSHA: "489d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name4",
|
|
},
|
|
},
|
|
nil,
|
|
)
|
|
filters := []v1alpha1.PullRequestGeneratorFilter{
|
|
{
|
|
TitleMatch: new("\\[filter]"),
|
|
},
|
|
{
|
|
TitleMatch: new("- filter"),
|
|
},
|
|
}
|
|
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
|
require.NoError(t, err)
|
|
assert.Len(t, pullRequests, 2)
|
|
assert.Equal(t, "one", pullRequests[0].Branch)
|
|
assert.Equal(t, "three", pullRequests[1].Branch)
|
|
}
|
|
|
|
func TestMultiFilterOr(t *testing.T) {
|
|
t.Parallel()
|
|
provider, _ := NewFakeService(
|
|
t.Context(),
|
|
[]*PullRequest{
|
|
{
|
|
Number: 1,
|
|
Title: "PR one",
|
|
Branch: "one",
|
|
TargetBranch: "master",
|
|
HeadSHA: "189d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name1",
|
|
},
|
|
{
|
|
Number: 2,
|
|
Title: "PR two",
|
|
Branch: "two",
|
|
TargetBranch: "master",
|
|
HeadSHA: "289d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name2",
|
|
},
|
|
{
|
|
Number: 3,
|
|
Title: "PR three",
|
|
Branch: "three",
|
|
TargetBranch: "master",
|
|
HeadSHA: "389d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name3",
|
|
},
|
|
{
|
|
Number: 4,
|
|
Title: "PR four",
|
|
Branch: "four",
|
|
TargetBranch: "master",
|
|
HeadSHA: "489d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name4",
|
|
},
|
|
},
|
|
nil,
|
|
)
|
|
filters := []v1alpha1.PullRequestGeneratorFilter{
|
|
{
|
|
BranchMatch: new("w"),
|
|
},
|
|
{
|
|
BranchMatch: new("r"),
|
|
},
|
|
}
|
|
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
|
require.NoError(t, err)
|
|
assert.Len(t, pullRequests, 3)
|
|
assert.Equal(t, "two", pullRequests[0].Branch)
|
|
assert.Equal(t, "three", pullRequests[1].Branch)
|
|
assert.Equal(t, "four", pullRequests[2].Branch)
|
|
}
|
|
|
|
func TestMultiFilterOrWithTargetBranchFilterOrWithTitleFilter(t *testing.T) {
|
|
t.Parallel()
|
|
provider, _ := NewFakeService(
|
|
t.Context(),
|
|
[]*PullRequest{
|
|
{
|
|
Number: 1,
|
|
Title: "PR one",
|
|
Branch: "one",
|
|
TargetBranch: "master",
|
|
HeadSHA: "189d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name1",
|
|
},
|
|
{
|
|
Number: 2,
|
|
Title: "PR two",
|
|
Branch: "two",
|
|
TargetBranch: "branch1",
|
|
HeadSHA: "289d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name2",
|
|
},
|
|
{
|
|
Number: 3,
|
|
Title: "PR three",
|
|
Branch: "three",
|
|
TargetBranch: "branch2",
|
|
HeadSHA: "389d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name3",
|
|
},
|
|
{
|
|
Number: 4,
|
|
Title: "PR four",
|
|
Branch: "four",
|
|
TargetBranch: "branch3",
|
|
HeadSHA: "489d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name4",
|
|
},
|
|
{
|
|
Number: 5,
|
|
Title: "PR title is different than branch name",
|
|
Branch: "five",
|
|
TargetBranch: "branch3",
|
|
HeadSHA: "489d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name5",
|
|
},
|
|
},
|
|
nil,
|
|
)
|
|
filters := []v1alpha1.PullRequestGeneratorFilter{
|
|
{
|
|
BranchMatch: new("w"),
|
|
TargetBranchMatch: new("1"),
|
|
},
|
|
{
|
|
BranchMatch: new("r"),
|
|
TargetBranchMatch: new("3"),
|
|
},
|
|
{
|
|
TitleMatch: new("two"),
|
|
},
|
|
{
|
|
BranchMatch: new("five"),
|
|
TitleMatch: new("PR title is different than branch name"),
|
|
},
|
|
}
|
|
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
|
require.NoError(t, err)
|
|
assert.Len(t, pullRequests, 3)
|
|
assert.Equal(t, "two", pullRequests[0].Branch)
|
|
assert.Equal(t, "four", pullRequests[1].Branch)
|
|
assert.Equal(t, "five", pullRequests[2].Branch)
|
|
assert.Equal(t, "PR title is different than branch name", pullRequests[2].Title)
|
|
}
|
|
|
|
func TestNoFilters(t *testing.T) {
|
|
t.Parallel()
|
|
provider, _ := NewFakeService(
|
|
t.Context(),
|
|
[]*PullRequest{
|
|
{
|
|
Number: 1,
|
|
Title: "PR one",
|
|
Branch: "one",
|
|
TargetBranch: "master",
|
|
HeadSHA: "189d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name1",
|
|
},
|
|
{
|
|
Number: 2,
|
|
Title: "PR two",
|
|
Branch: "two",
|
|
TargetBranch: "master",
|
|
HeadSHA: "289d92cbf9ff857a39e6feccd32798ca700fb958",
|
|
Author: "name2",
|
|
},
|
|
},
|
|
nil,
|
|
)
|
|
filters := []v1alpha1.PullRequestGeneratorFilter{}
|
|
repos, err := ListPullRequests(t.Context(), provider, filters)
|
|
require.NoError(t, err)
|
|
assert.Len(t, repos, 2)
|
|
assert.Equal(t, "one", repos[0].Branch)
|
|
assert.Equal(t, "two", repos[1].Branch)
|
|
}
|