Skip to content

Commit

Permalink
Migrate tests to GitHub Actions (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi authored Oct 1, 2023
1 parent e9c98c6 commit 47f68e3
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 70 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Tests
on:
push:
branches:
- '**'
tags-ignore:
- '**'
# Triggers the workflow on labeled PRs only.
pull_request_target:
types: [ labeled ]
# Ensures that only the latest commit is running for each PR at a time.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.ref }}
cancel-in-progress: true
jobs:
Tests:
if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push'
name: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu, windows, macOS ]
include:
- os: windows
gradlewSuffix: .bat
runs-on: ${{ matrix.os }}-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
cache: false
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Artifactory
run: |
go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest
~/go/bin/local-rt-setup
env:
RTLIC: ${{secrets.RTLIC}}
GOPROXY: direct

- name: Install Java
uses: actions/setup-java@v3
with:
java-version: "8"
distribution: "temurin"

- name: Run tests
run: ./gradlew${{ matrix.gradlewSuffix }} clean test
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

[![Scanned by Frogbot](https://raw.github.com/jfrog/frogbot/master/images/frogbot-badge.svg)](https://github.com/jfrog/frogbot#readme)

|Branch|Status|
|:---:|:---:|
|master|[![Build status](https://ci.appveyor.com/api/projects/status/sarjlbpi6dfgrd5w/branch/master?svg=true)](https://ci.appveyor.com/project/jfrog-ecosystem/artifactory-client-java/branch/master)
|dev|[![Build status](https://ci.appveyor.com/api/projects/status/sarjlbpi6dfgrd5w/branch/dev?svg=true)](https://ci.appveyor.com/project/jfrog-ecosystem/artifactory-client-java/branch/dev)
| Branch |Status|
|:------:|:---:|
|master|[![Test](https://github.com/jfrog/artifactory-client-java/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/jfrog/artifactory-client-java/actions/workflows/tests.yml?query=branch%3Amaster)
|dev|[![Test](https://github.com/jfrog/artifactory-client-java/actions/workflows/tests.yml/badge.svg?branch=dev)](https://github.com/jfrog/artifactory-client-java/actions/workflows/tests.yml?query=branch%3Adev)

</div>

Expand Down
20 changes: 0 additions & 20 deletions ci/appveyor.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jfrog.artifactory.client;

import org.apache.http.client.HttpResponseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
Expand All @@ -13,17 +14,18 @@
import org.jfrog.artifactory.client.model.repository.settings.impl.MavenRepositorySettingsImpl;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Properties;

import static org.apache.commons.codec.binary.Base64.encodeBase64;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.remove;
import static org.testng.Assert.fail;

/**
* @author jbaruch
Expand Down Expand Up @@ -58,12 +60,12 @@ public void init() throws IOException {
props.load(inputStream);
}

url = readParam(props, "url");
url = readParam(props, "url", "http://localhost:8081/artifactory");
if (!url.endsWith("/")) {
url += "/";
}
username = readParam(props, "username");
password = readParam(props, "password");
username = readParam(props, "username", "admin");
password = readParam(props, "password", "password");
filePath = "a/b";
fileSize = 141185;
fileMd5 = "8f17d4271b86478a2731deebdab8c846";
Expand Down Expand Up @@ -97,39 +99,12 @@ public void init() throws IOException {
}
}

public static String readParam(Properties props, String paramName) {
String paramValue = null;
if (props.size() > 0) {
paramValue = props.getProperty(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX + paramName);
}
if (paramValue == null) {
paramValue = System.getProperty(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX + paramName);
}
if (paramValue == null) {
paramValue = System.getenv(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX + paramName.toUpperCase());
}
if (paramValue == null) {
failInit();
}
return paramValue;
}

private static void failInit() {
String message =
new StringBuilder("Failed to load test Artifactory instance credentials. ")
.append("Looking for System properties '")
.append(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX)
.append("url', ")
.append(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX)
.append("username' and ")
.append(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX)
.append("password' or a properties file with those properties in classpath ")
.append("or Environment variables '")
.append(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX).append("URL', ")
.append(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX).append("USERNAME' and ")
.append(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX).append("PASSWORD'").toString();

fail(message);
public static String readParam(Properties props, String paramName, String defaultValue) {
return StringUtils.firstNonBlank(
props.getProperty(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX + paramName),
System.getProperty(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX + paramName),
System.getenv(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX + paramName.toUpperCase()),
defaultValue);
}

@AfterClass
Expand Down Expand Up @@ -208,8 +183,8 @@ protected String deleteRepoIfExists(String repoName) {
try {
return artifactory.repository(repoName).delete();
} catch (Exception e) {
if (e instanceof HttpResponseException && ((HttpResponseException)e).getStatusCode() == 404) {
//if repo wasn't found - that's ok.
if (e instanceof HttpResponseException && ((HttpResponseException) e).getStatusCode() == 404) {
//if repo wasn't found - that's ok.
return e.getMessage();
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ public void testErrorStreamingRestCall() throws IOException {
assertFalse(response.isSuccessResponse());
assertEquals(response.getStatusLine().getStatusCode(), 404);
String raw = IOUtils.toString(response.getInputStream(), StandardCharsets.UTF_8);
assertEquals(raw, "{\n" +
" \"errors\" : [ {\n" +
" \"status\" : 404,\n" +
" \"message\" : \"File not found.\"\n" +
" } ]\n" +
"}");
assertTrue(raw.contains("File not found"), "Expected response to contain 'File not found'.\nResponse:" + raw);
}
}

0 comments on commit 47f68e3

Please sign in to comment.