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

Add support for SCM tests on gitlab and bitbucket #1220

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ jobs:
GCP_SERVICE_ACCOUNT_PATH: '${{ github.workspace }}/key_file.json'
SCM_TEST_REPO_URL: ${{ secrets.SCM_TEST_REPO_URL }}
SCM_TEST_REPO_PAT: ${{ secrets.SCM_TEST_REPO_PAT }}
SCM_TEST_REPO_URL_GITLAB: ${{ secrets.SCM_TEST_REPO_URL_GITLAB }}
SCM_TEST_REPO_PAT_GITLAB: ${{ secrets.SCM_TEST_REPO_PAT_GITLAB }}
SCM_TEST_REPO_URL_BITBUCKET: ${{ secrets.SCM_TEST_REPO_URL_BITBUCKET }}
SCM_TEST_REPO_PAT_BITBUCKET: ${{ secrets.SCM_TEST_REPO_PAT_BITBUCKET }}
run: |
echo $GCP_SERVICE_ACCOUNT_CONTENTS > ./key_file.json
yarn run cdap-full-build-more-memory # Build UI
Expand Down
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<version>0.10</version>
<version>0.11</version>
<executions>
<execution>
<id>rat-check</id>
Expand Down Expand Up @@ -599,6 +599,8 @@
<configuration>
<includes>
<include>TestRunner.java</include>
<include>TestRunnerWithGitlab.java</include>
<include>TestRunnerWithBitbucket.java</include>
</includes>
<parallel>classes</parallel> <!--Running TestRunner classes in parallel-->
<threadCount>4</threadCount> <!--Number of classes to run in parallel-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# the License.
#

@Integration_Tests
@Integration_Tests @SCM_GITHUB_TEST @SCM_GITLAB_TEST @SCM_BITBUCKET_TEST
Feature: Source Control Management - Repository Configuration CRUD operations

@SOURCE_CONTROL_MANAGEMENT_TEST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# the License.
#

@Integration_Tests
@Integration_Tests @SCM_GITHUB_TEST @SCM_GITLAB_TEST @SCM_BITBUCKET_TEST
Feature: Source Control Management - Pulling and pushing applications
Background:
When Open Source Control Management Page
Expand Down
2 changes: 1 addition & 1 deletion src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/e2e-test/features"},
glue = {"io.cdap.cdap.ui.stepsdesign", "stepsdesign"},
glue = {"io.cdap.cdap.ui.stepsdesign", "io.cdap.cdap.ui.testconfig.github", "stepsdesign"},
tags = {"not @ignore"},
plugin = {"pretty", "html:target/cucumber-html-report/tethering",
"json:target/cucumber-reports/cucumber-tethering.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © 2024 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package io.cdap.cdap.ui.runners;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

/**
* Test Runner to execute namespace creation related test cases.
*/
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/e2e-test/features"},
glue = {"io.cdap.cdap.ui.stepsdesign", "io.cdap.cdap.ui.testconfig.bitbucket", "stepsdesign"},
tags = {"@SCM_BITBUCKET_TEST"},
plugin = {"pretty", "html:target/cucumber-html-report/tethering",
"json:target/cucumber-reports/cucumber-tethering.json",
"junit:target/cucumber-reports/cucumber-tethering.xml"}
)
public class TestRunnerWithBitbucket {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © 2024 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package io.cdap.cdap.ui.runners;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

/**
* Test Runner to execute namespace creation related test cases.
*/
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/e2e-test/features"},
glue = {"io.cdap.cdap.ui.stepsdesign", "io.cdap.cdap.ui.testconfig.gitlab", "stepsdesign"},
tags = {"@SCM_GITLAB_TEST"},
plugin = {"pretty", "html:target/cucumber-html-report/tethering",
"json:target/cucumber-reports/cucumber-tethering.json",
"junit:target/cucumber-reports/cucumber-tethering.xml"}
)
public class TestRunnerWithGitlab {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
import io.cdap.cdap.ui.utils.Constants;
import io.cdap.cdap.ui.utils.Helper;
import io.cucumber.java.After;
import org.eclipse.jgit.api.errors.GitAPIException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -41,9 +38,4 @@ public static void cleanupDownloadDirectory() {
Helper.cleanupDirectory(downloadsDir);
}
}

@After(order = 1, value = "@SOURCE_CONTROL_MANAGEMENT_TEST")
public void cleanUpTestBranch() throws IOException, GitAPIException {
Helper.cleanupSCMTestBranch();
}
}
28 changes: 1 addition & 27 deletions src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/BeforeActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@

package io.cdap.cdap.ui.stepsdesign;

import com.google.common.base.Strings;
import io.cdap.cdap.ui.utils.Constants;
import io.cdap.cdap.ui.utils.Helper;
import io.cdap.e2e.utils.PluginPropertyUtils;
import io.cucumber.java.Before;
import org.eclipse.jgit.api.errors.GitAPIException;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.UUID;

public class BeforeActions {
private static final Logger logger = LoggerFactory.getLogger(stepsdesign.BeforeActions.class);

Expand All @@ -36,24 +30,4 @@ public void loginIfRequired() throws IOException {
logger.info("-----------------Logging in if required------------------");
Helper.loginIfRequired();
}

@Before(order = 1, value = "@SOURCE_CONTROL_MANAGEMENT_TEST")
public void createGitBranchConfig() throws GitAPIException, IOException {
String gitRepoUrl = System.getenv("SCM_TEST_REPO_URL");
if (!Strings.isNullOrEmpty(gitRepoUrl)) {
PluginPropertyUtils.addPluginProp(Constants.GIT_REPO_URL_PROP_NAME, gitRepoUrl);
}

String gitPAT = System.getenv("SCM_TEST_REPO_PAT");
if (!Strings.isNullOrEmpty(gitPAT)) {
PluginPropertyUtils.addPluginProp(Constants.GIT_PAT_PROP_NAME, gitPAT);
}

if (Strings.isNullOrEmpty(PluginPropertyUtils.pluginProp(Constants.GIT_BRANCH_PROP_NAME))) {
String branchName = "cdf-e2e-test-" + UUID.randomUUID();
PluginPropertyUtils.addPluginProp(Constants.GIT_BRANCH_PROP_NAME, branchName);
}

Helper.createSCMRemoteBranch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public void openAddRepositoryButton() {
ElementHelper.clickOnElement(Helper.locateElementByTestId("link-repository-button"));
}

private void selectScmProvider(String providerType) {
WebElement scmProviderSelect = Helper.locateElementByTestId("select-provider");
ElementHelper.clickOnElement(scmProviderSelect);
WebElement providerOption = Helper.locateElementByTestId("option-" + providerType);
WaitHelper.waitForElementToBeDisplayed(providerOption);
ElementHelper.clickOnElement(providerOption);
}

private void addRepoUrl(String repoUrl) {
WebElement repoUrlInput = Helper.locateElementByTestId("repoUrl");
ElementHelper.clearElementValue(repoUrlInput);
Expand Down Expand Up @@ -122,6 +130,7 @@ public void addFakeRepositoryConfiguration() {

@Then("Add test repository configuration")
public void addTestRepositoryConfiguration() {
selectScmProvider(PluginPropertyUtils.pluginProp(Constants.SCM_PROVIDER_PROP_NAME));
addRepoUrl(PluginPropertyUtils.pluginProp(Constants.GIT_REPO_URL_PROP_NAME));
addTokenName(Constants.FAKE_TOKEN_NAME);
addToken(PluginPropertyUtils.pluginProp(Constants.GIT_PAT_PROP_NAME));
Expand Down Expand Up @@ -174,6 +183,7 @@ public void pipelineBannerIsShownWithMessage(String message) {
@When("Initialize the repository config")
public void initializeRepoConfig() {
openAddRepositoryButton();
selectScmProvider(PluginPropertyUtils.pluginProp(Constants.SCM_PROVIDER_PROP_NAME));
addRepoUrl(PluginPropertyUtils.pluginProp(Constants.GIT_REPO_URL_PROP_NAME));
addToken(PluginPropertyUtils.pluginProp(Constants.GIT_PAT_PROP_NAME));
addTokenName("e2e-test-token");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright © 2024 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package io.cdap.cdap.ui.testconfig.bitbucket;

import io.cdap.cdap.ui.utils.Helper;
import io.cdap.cdap.ui.utils.ScmProviderType;
import io.cucumber.java.After;
import java.io.IOException;
import org.eclipse.jgit.api.errors.GitAPIException;

public class AfterActions {
@After(order = 1, value = "@SCM_BITBUCKET_TEST")
public void cleanUpTestBranch() throws IOException, GitAPIException {
Helper.cleanupSCMTestBranch(ScmProviderType.BITBUCKET_CLOUD);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright © 2024 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package io.cdap.cdap.ui.testconfig.bitbucket;

import io.cdap.cdap.ui.testconfig.common.ScmConfigHelper;
import io.cdap.cdap.ui.utils.Constants;
import io.cdap.cdap.ui.utils.Helper;
import io.cdap.cdap.ui.utils.ScmProviderType;
import io.cdap.e2e.utils.PluginPropertyUtils;
import io.cucumber.java.Before;
import java.io.IOException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BeforeActions {
private static final Logger logger = LoggerFactory.getLogger(stepsdesign.BeforeActions.class);

@Before(order = 1, value = "@SCM_BITBUCKET_TEST")
public void createBitbucketBranchConfig() throws GitAPIException, IOException {
logger.info("----------------- Using bitbucket for SCM ------------------");
PluginPropertyUtils.addPluginProp(Constants.SCM_PROVIDER_PROP_NAME, "BITBUCKET_CLOUD");
ScmConfigHelper.setupScmCredentials(
"SCM_TEST_REPO_URL_BITBUCKET",
"SCM_TEST_REPO_PAT_BITBUCKET");
Helper.createSCMRemoteBranch(ScmProviderType.BITBUCKET_CLOUD);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright © 2024 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package io.cdap.cdap.ui.testconfig.common;

import com.google.common.base.Strings;
import io.cdap.cdap.ui.utils.Constants;
import io.cdap.e2e.utils.PluginPropertyUtils;
import java.util.UUID;

public class ScmConfigHelper {
public static void setupScmCredentials(String repoUrlVarName, String repoPatVarName) {
String gitRepoUrl = System.getenv(repoUrlVarName);
if (!Strings.isNullOrEmpty(gitRepoUrl)) {
PluginPropertyUtils.addPluginProp(Constants.GIT_REPO_URL_PROP_NAME, gitRepoUrl);
}

String gitPAT = System.getenv(repoPatVarName);
if (!Strings.isNullOrEmpty(gitPAT)) {
PluginPropertyUtils.addPluginProp(Constants.GIT_PAT_PROP_NAME, gitPAT);
}

if (Strings.isNullOrEmpty(PluginPropertyUtils.pluginProp(Constants.GIT_BRANCH_PROP_NAME))) {
String branchName = "cdf-e2e-test-" + UUID.randomUUID();
PluginPropertyUtils.addPluginProp(Constants.GIT_BRANCH_PROP_NAME, branchName);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright © 2024 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package io.cdap.cdap.ui.testconfig.github;

import io.cdap.cdap.ui.utils.Helper;
import io.cdap.cdap.ui.utils.ScmProviderType;
import io.cucumber.java.After;
import java.io.IOException;
import org.eclipse.jgit.api.errors.GitAPIException;

public class AfterActions {
@After(order = 1, value = "@SCM_GITHUB_TEST")
public void cleanUpTestBranch() throws IOException, GitAPIException {
Helper.cleanupSCMTestBranch(ScmProviderType.GITHUB);
}
}
Loading
Loading