Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix flaky e2e test #11670

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 41 additions & 11 deletions test/e2e/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ func TestSimpleGitFilesPreserveResourcesOnDeletionGoTemplate(t *testing.T) {
}).Then().Expect(Pod(func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") }))
}

func githubMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
func githubSCMMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.RequestURI {
Expand Down Expand Up @@ -979,7 +979,7 @@ func githubMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
func TestSimpleSCMProviderGenerator(t *testing.T) {
// Use mocked API response to avoid rate-limiting.
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
githubMockHandler(t)(w, r)
githubSCMMockHandler(t)(w, r)
}))

expectedApp := argov1alpha1.Application{
Expand Down Expand Up @@ -1052,7 +1052,7 @@ func TestSimpleSCMProviderGenerator(t *testing.T) {
func TestSimpleSCMProviderGeneratorGoTemplate(t *testing.T) {
// Use mocked API response to avoid rate-limiting.
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
githubMockHandler(t)(w, r)
githubSCMMockHandler(t)(w, r)
}))

expectedApp := argov1alpha1.Application{
Expand Down Expand Up @@ -1256,11 +1256,39 @@ func TestCustomApplicationFinalizersGoTemplate(t *testing.T) {
Delete().Then().Expect(ApplicationsDoNotExist([]argov1alpha1.Application{expectedApp}))
}

func TestSimplePullRequestGenerator(t *testing.T) {

if utils.IsGitHubAPISkippedTest(t) {
return
func githubPullMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.RequestURI {
case "/api/v3/repos/applicationset-test-org/argocd-example-apps/pulls?per_page=100":
_, err := io.WriteString(w, `[
{
"number": 1,
"labels": [
{
"name": "preview"
}
],
"head": {
"ref": "pull-request",
"sha": "824a5c987fdfb2b0629e9dbf5f31636c69ba4772"
}
}
]`)
if err != nil {
t.Fail()
}
default:
w.WriteHeader(404)
}
}
}

func TestSimplePullRequestGenerator(t *testing.T) {
// Use mocked API response to avoid rate-limiting.
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
githubPullMockHandler(t)(w, r)
}))

expectedApp := argov1alpha1.Application{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -1317,6 +1345,7 @@ func TestSimplePullRequestGenerator(t *testing.T) {
{
PullRequest: &v1alpha1.PullRequestGenerator{
Github: &v1alpha1.PullRequestGeneratorGithub{
API: ts.URL,
Owner: "applicationset-test-org",
Repo: "argocd-example-apps",
Labels: []string{
Expand All @@ -1331,10 +1360,10 @@ func TestSimplePullRequestGenerator(t *testing.T) {
}

func TestSimplePullRequestGeneratorGoTemplate(t *testing.T) {

if utils.IsGitHubAPISkippedTest(t) {
return
}
// Use mocked API response to avoid rate-limiting.
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
githubPullMockHandler(t)(w, r)
}))

expectedApp := argov1alpha1.Application{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -1395,6 +1424,7 @@ func TestSimplePullRequestGeneratorGoTemplate(t *testing.T) {
{
PullRequest: &v1alpha1.PullRequestGenerator{
Github: &v1alpha1.PullRequestGeneratorGithub{
API: ts.URL,
Owner: "applicationset-test-org",
Repo: "argocd-example-apps",
Labels: []string{
Expand Down