Skip to content

Commit

Permalink
chore: fix flaky e2e test (argoproj#11670)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
  • Loading branch information
crenshaw-dev authored and emirot committed Jan 27, 2023
1 parent 20be8f2 commit df0ff7d
Showing 1 changed file with 41 additions and 11 deletions.
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

0 comments on commit df0ff7d

Please sign in to comment.