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

Run acceptance tests in both github and gitlab #1245

Merged
merged 46 commits into from Jan 5, 2022

Conversation

rokshana-b
Copy link
Contributor

@rokshana-b rokshana-b commented Dec 17, 2021

Closes: #1251

What changed?

  • Added a new env called GIT_PROVIDER for test runs
  • Changed the run test job to run 2 test cases on parallel
  • Refactored add tests & install tests to adapt to the new env
  • Refactored a test case to include test scenario: create a pr for app deletion

Why?

  • To supply the new env for test runs depending on github/gitlab
  • To cover smoke tests for both github/gitlab scenarios
  • To cover test scenario where a pr is created for app deletion when --auto-merge flag is skipped

How did you test it?

  • Locally
  • CI

@rokshana-b rokshana-b linked an issue Dec 20, 2021 that may be closed by this pull request
Copy link
Contributor

@iahmad9 iahmad9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@josecordaz josecordaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a lot of changes here, I have to recongince the effort you put on doing all this modifications. Great work.

test/acceptance/test/utils.go Outdated Show resolved Hide resolved
func setGitProvider() (gitproviders.GitProviderName, string, string) {
gitlab := "gitlab"
github := "github"
gitProvider := os.Getenv("GIT_PROVIDER")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use os.LookupEnv(key) instead, it will help in knowing if this env is set or not. Which is relevant when we run tests locally. In that case and even for CI, you could add some logic saying we need to set this environment variable for tests to work properly(or something similar), otherwise running tests locally will fail, and we would need to debug just to find out that missing this env was the actual problem. If possible I would move this logic to here https://github.com/weaveworks/weave-gitops/blob/main/test/acceptance/test/testsuite_common_test.go#L52 as this already does what I'm suggesting. And it helps to have one single place for the same logic patterns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the tests won't fail even if the env is not set. The function returns github by default even if the env is missing. Si the tests would run on github by default. The only change this function brings is if we want to run all the github tests in gitlab repos. I don't want this variable set as a requirement because I avoided using this env for specific gitlab tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I would argue then that we should have some doc explaining this behavior and also how to run all this cases, like:

  • How to run github tests in gitlab
  • How to run gitlab tests
  • How to run github tests

BTW if you need to have a different value for specific variable in one of the tests you can add it to that specific test only. Like here for instance https://github.com/weaveworks/weave-gitops/blob/main/test/integration/server/remove_test.go#L254. This AutoMerge variable is not needed in all cases only on that specific one. If you ever need to use something specific in more than one test, and you want to avoid writting it twice , you could add a new Context and set that variable's value in a BeforeEach within that context. Like this for instance https://github.com/weaveworks/weave-gitops/blob/main/test/integration/server/remove_test.go#L223. gitlabGroup was written once but it runs for each test within that context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can definitely update the ReadME file for clarification

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update the ReadME in a follow up PR and try to see if setting git-provider variables at BeforeSuite works. For now, I'm merging this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVM, I updated the readme and set the variables at suite level.

@@ -845,3 +846,18 @@ func getGitProvider(org string, repo string, providerName gitproviders.GitProvid

return gitProvider, orgRef, err
}

func setGitProvider() (gitproviders.GitProviderName, string, string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use this logic only once here https://github.com/weaveworks/weave-gitops/blob/main/test/acceptance/test/testsuite_common_test.go#L52 instead of calling it multiple time in each BeforeEach. If you want to keep this function and call it once in BeforeSuite it's fine I would just suggest changing the function name to something more align to its functionality, maybe something like getGitProviderInfo,getGitProviderData or something similar. Usually methods with set in their name are meant to receive parameters and do not return values.

test/acceptance/test/add_tests.go Outdated Show resolved Hide resolved
@@ -71,7 +74,7 @@ runs:
run: |
chmod +x bin/gitops
ls -la bin
- name: Download dependecies
- name: Download dependencies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

.github/workflows/test.yml Outdated Show resolved Hide resolved
josecordaz and others added 5 commits December 22, 2021 23:39
* Attempt to fix env vars by using double quotes

* Print out git provider value

* Print out git provider value

* Removed extra dollar simbol

* Removed debug code
@rokshana-b rokshana-b merged commit 4130da6 into main Jan 5, 2022
@rokshana-b rokshana-b deleted the use-git-provider-as-variable branch January 5, 2022 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run acceptance tests on parallel for github and gitlab
3 participants