Skip to content

Commit a68c3ac

Browse files
authored
E2E tests (#58)
* Add E2E tests
1 parent 5190506 commit a68c3ac

24 files changed

+1140
-133
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- [ ] The code has been formatted properly using `go fmt ./...`.
44
- [ ] All [static analysis checks](https://github.com/jfrog/jfrog-cli-application/actions/workflows/analysis.yml) passed.
55
- [ ] All [tests](https://github.com/jfrog/jfrog-cli-application/actions/workflows/tests.yml) have passed. If this feature is not already covered by the tests, new tests have been added.
6-
- [ ] All integration tests have passed locally as they cannot be automated yet.
7-
- [ ] All changes are detailed at the description. if not already covered at [JFrog Documentation](https://github.com/jfrog/documentation), new documentation have been added.
6+
- [ ] All [E2E tests](https://github.com/jfrog/jfrog-cli-application/actions/workflows/e2e-tests.yml) have passed.
7+
- [ ] All changes are detailed at the description.
88

9-
-----
9+
-----

.github/workflows/e2e-tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: E2E Tests
2+
on:
3+
push:
4+
branches:
5+
- '**'
6+
tags-ignore:
7+
- '**'
8+
workflow_dispatch:
9+
pull_request_target:
10+
types: [ labeled ]
11+
# Ensures that only the latest commit is running for each PR at a time.
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
jobs:
16+
e2e-tests:
17+
# To avoid running code from untrusted contributors without review, we only run E2E tests on PRs labeled 'safe to test'
18+
if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
19+
name: E2E tests
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Unlabel 'safe to test'
23+
uses: actions-ecosystem/action-remove-labels@v1
24+
if: ${{ github.event_name != 'push' && github.event_name != 'workflow_dispatch' }}
25+
with:
26+
labels: "safe to test"
27+
28+
- name: Checkout code
29+
uses: actions/checkout@v6
30+
with:
31+
ref: ${{ github.event.pull_request.head.sha }}
32+
33+
- name: Setup Go
34+
uses: actions/setup-go@v6
35+
with:
36+
go-version-file: go.mod
37+
38+
- name: Run E2E Tests
39+
run: |
40+
make e2e-test-ci
41+
env:
42+
JFROG_APPTRUST_CLI_TESTS_JFROG_URL: ${{ secrets.JFROG_APPTRUST_CLI_TESTS_JFROG_URL }}
43+
JFROG_APPTRUST_CLI_TESTS_JFROG_ACCESS_TOKEN: ${{ secrets.JFROG_APPTRUST_CLI_TESTS_JFROG_ACCESS_TOKEN }}
44+
45+
- name: Publish Results
46+
uses: EnricoMi/publish-unit-test-result-action@v2
47+
if: always()
48+
with:
49+
files: |
50+
e2e-tests-report.xml

.github/workflows/tests.yml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
name: Go Tests
1+
name: Tests
22
on:
33
push:
4-
branches:
5-
- '**'
6-
tags-ignore:
7-
- '**'
84
workflow_dispatch:
9-
pull_request_target:
5+
pull_request:
106
# Ensures that only the latest commit is running for each PR at a time.
117
concurrency:
128
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.ref }}
@@ -16,22 +12,13 @@ jobs:
1612
name: Unit tests
1713
runs-on: ubuntu-latest
1814
steps:
19-
2015
- name: Checkout code
21-
uses: actions/checkout@v4
16+
uses: actions/checkout@v6
2217

2318
- name: Setup Go
24-
uses: actions/setup-go@v5
19+
uses: actions/setup-go@v6
2520
with:
2621
go-version-file: go.mod
27-
cache: false
28-
29-
- name: Go Cache
30-
uses: actions/cache@v4
31-
with:
32-
path: ~/go/pkg/mod
33-
key: go-${{ hashFiles('**/go.sum') }}
34-
restore-keys: go-
3522

3623
- name: Run Tests
3724
run: |
@@ -41,6 +28,5 @@ jobs:
4128
uses: EnricoMi/publish-unit-test-result-action@v2
4229
if: always()
4330
with:
44-
check_name: Unit Tests Results
4531
files: |
4632
utests-report.xml

CONTRIBUTING.md

Lines changed: 7 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -19,108 +19,27 @@ go run github.com/jfrog/jfrog-cli-application command [options] [arguments...]
1919

2020
---
2121

22-
This project heavily depends on the following modules:
23-
24-
- [github.com/jfrog/jfrog-client-go](https://github.com/jfrog/jfrog-client-go)
25-
- [github.com/jfrog/jfrog-cli-core](github.com/jfrog/jfrog-cli-core)
26-
27-
During local development, if you come across code that needs to be modified in one of the mentioned modules, it is advisable to replace the dependency with a local clone of the module.
28-
29-
<details>
30-
<summary>Replacing a dependency with a local clone</summary>
31-
32-
---
33-
34-
To include this local dependency, For instance, let's assume you wish to modify files from `jfrog-cli-core`, modify the `go.mod` file as follows:
35-
36-
```
37-
replace github.com/jfrog/jfrog-cli-core/v2 => /local/path/in/your/machine/jfrog-cli-core
38-
```
39-
40-
Afterward, execute `go mod tidy` to ensure the Go module files are updated. Note that Go will automatically adjust the version in the `go.mod` file.
41-
42-
---
43-
44-
</details>
45-
46-
4722
## 🚦 Running Tests
4823

49-
When running tests, builds and repositories with timestamps like `cli-rt1-1592990748` and `cli-rt2-1592990748` will be created. The content of these repositories will be deleted once the tests are completed.
50-
51-
To run tests, use the following command:
24+
To run unit tests, use the following command:
5225

5326
```
54-
go test -v github.com/jfrog/jfrog-cli-application [test-types] [flags]
27+
make test
5528
```
5629

57-
### The available flags are:
58-
59-
| Flag | Description |
60-
| ------------------- | ----------------------------------------------------------------------------------------------- |
61-
| `-jfrog.url` | [Default: http://localhost:8081] JFrog platform URL |
62-
| `-jfrog.user` | [Default: admin] JFrog platform username |
63-
| `-jfrog.password` | [Default: password] JFrog platform password |
64-
| `-jfrog.adminToken` | [Optional] JFrog platform admin token |
65-
| `-ci.runId` | [Optional] A unique identifier used as a suffix to create repositories and builds in the tests. |
66-
| `-jfrog.sshKeyPath` | [Optional] Path to the SSH key file. Use this flag only if the Artifactory URL format is `ssh://[domain]:port`. |
67-
| `-jfrog.sshPassphrase` | [Optional] Passphrase for the SSH key. |
30+
To run end-to-end (E2E) tests, refer to the README file located in the `e2e` directory.
6831

6932
---
7033

71-
72-
### The available test types are:
73-
74-
| Type | Description |
75-
| -------------------- | ------------------ |
76-
| `-test.security` | [Default: true] Security commands integration tests |
77-
| `-test.dockerScan` | [Optional] Docker scan integration tests |
78-
79-
### Docker Scan tests
80-
81-
<details>
82-
83-
#### Requirements
84-
85-
- Make sure the `RTLIC` environment variable is configured with a valid license.
86-
- Before running the tests, wait for Artifactory to finish booting up in the container.
87-
88-
| Flag | Description |
89-
| ------------------------- | ----------------------------------- |
90-
| `-test.containerRegistry` | Artifactory Docker registry domain. |
91-
92-
93-
</details>
94-
9534
## 📖 Submitting PR Guidelines
9635

97-
Once you have completed your coding changes, it is recommended to push the modifications made to the other modules first. Once these changes are pushed, you can update this project to resolve dependencies from your GitHub fork or branch.
98-
99-
<details>
100-
101-
<summary>Resolve dependencies from GitHub fork or branch</summary>
102-
103-
---
104-
105-
To achieve this, modify the `go.mod` file to point the dependency to your repository and branch, as shown in the example below:
106-
107-
```
108-
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 dev
109-
```
110-
111-
Finally, execute `go mod tidy` to update the Go module files. Please note that Go will automatically update the version in the `go.mod` file.
112-
113-
---
114-
115-
</details>
116-
11736
### Before submitting the pull request, ensure:
11837

119-
- Your changes are covered by `unit` and `integration` tests. If not, please add new tests.
120-
- The documentation covers the changes, if not please add and make changes at [The documentation repository](https://github.com/jfrog/documentation)
121-
- Run the go linter with --fix flag `golangci-lint run --fix`
38+
- Your changes are covered by `unit` and `e2e` tests. If not, please add new tests.
39+
- The code has been validated to compile successfully by running `go vet ./...`
40+
- The code has been formatted properly using `go fmt ./...`
12241

12342
### When creating the pull request, ensure:
12443

125-
- The pull request is on the `dev` branch.
44+
- The pull request is targeting the `main` branch.
12645
- The pull request description describes the changes made.

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ GOLANGCI_LINT:
4545

4646
########## BUILD ##########
4747
prereq::
48-
$(GOCMD) install github.com/jstemmer/go-junit-report/v2@latest
49-
GOBIN=${TOOLS_DIR} $(GOCMD) install go.uber.org/mock/mockgen@v0.5.0
48+
$(GOCMD) install gotest.tools/gotestsum@latest
49+
GOBIN=${TOOLS_DIR} $(GOCMD) install go.uber.org/mock/mockgen@v0.6.0
5050
${TOOLS_DIR}/mockgen --version
5151

5252
build:: clean generate-mock
@@ -82,5 +82,8 @@ test: PACKAGES=./...
8282
test: test-prereq
8383
go test ./...
8484
test-ci: test-prereq
85-
go test -v 2>&1 ./... | go-junit-report -set-exit-code -iocopy -out utests-report.xml
86-
85+
gotestsum --format testname --junitfile=utests-report.xml -- ./...
86+
e2e-test: test-prereq
87+
go test ./e2e/... -tags=e2e
88+
e2e-test-ci: test-prereq
89+
gotestsum --format testname --junitfile=e2e-tests-report.xml -- ./e2e/... -tags=e2e

apptrust/http/http_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const apptrustApiPath = "apptrust/api"
2424
type ApptrustHttpClient interface {
2525
GetHttpClient() *jfroghttpclient.JfrogHttpClient
2626
Post(path string, requestBody interface{}, params map[string]string) (resp *http.Response, body []byte, err error)
27-
Get(path string) (resp *http.Response, body []byte, err error)
27+
Get(path string, params map[string]string) (resp *http.Response, body []byte, err error)
2828
Patch(path string, requestBody interface{}) (resp *http.Response, body []byte, err error)
2929
Delete(path string, params map[string]string) (resp *http.Response, body []byte, err error)
3030
}
@@ -101,8 +101,8 @@ func (c *apptrustHttpClient) Post(path string, requestBody interface{}, params m
101101
return c.client.SendPost(url, requestContent, c.getJsonHttpClientDetails())
102102
}
103103

104-
func (c *apptrustHttpClient) Get(path string) (resp *http.Response, body []byte, err error) {
105-
url, err := utils.BuildUrl(c.serverDetails.Url, apptrustApiPath+path, nil)
104+
func (c *apptrustHttpClient) Get(path string, params map[string]string) (resp *http.Response, body []byte, err error) {
105+
url, err := utils.BuildUrl(c.serverDetails.Url, apptrustApiPath+path, params)
106106
if err != nil {
107107
return nil, nil, err
108108
}

apptrust/http/mocks/http_client_mock.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apptrust/service/systems/system_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func NewSystemService() SystemService {
2020
}
2121

2222
func (ss *systemService) Ping(ctx service.Context) error {
23-
response, body, err := ctx.GetHttpClient().Get("/v1/system/ping")
23+
response, body, err := ctx.GetHttpClient().Get("/v1/system/ping", nil)
2424
if err != nil {
2525
return err
2626
}

apptrust/service/systems/system_service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestSystemService_Ping(t *testing.T) {
5353
defer ctrl.Finish()
5454

5555
mockHttpClient := mockhttp.NewMockApptrustHttpClient(ctrl)
56-
mockHttpClient.EXPECT().Get("/v1/system/ping").
56+
mockHttpClient.EXPECT().Get("/v1/system/ping", nil).
5757
Return(tt.mockResponse, tt.mockBody, tt.mockError)
5858

5959
mockCtx := mockservice.NewMockContext(ctrl)

e2e/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# E2E Tests
2+
3+
## Running E2E Tests
4+
5+
### Prerequisites
6+
7+
1. Setup a JPD (JFrog Platform Deployment)
8+
2. Create an identity token with admin permissions
9+
10+
### Configuration
11+
12+
You can configure the tests using either environment variables or command-line flags.
13+
14+
#### Option 1: Environment Variables
15+
16+
Set the following environment variables:
17+
18+
* **JFROG_APPTRUST_CLI_TESTS_JFROG_URL**: The JFrog Platform URL (defaults to `http://localhost:8082/` if not set)
19+
* **JFROG_APPTRUST_CLI_TESTS_JFROG_ACCESS_TOKEN**: The JFrog Platform access token
20+
21+
Example:
22+
23+
```bash
24+
export JFROG_APPTRUST_CLI_TESTS_JFROG_URL=http://localhost:8082
25+
export JFROG_APPTRUST_CLI_TESTS_JFROG_ACCESS_TOKEN=your-access-token
26+
go test -tags=e2e ./e2e/...
27+
```
28+
29+
#### Option 2: Command-Line Flags
30+
31+
Use the `-jfrog.url` and `-jfrog.adminToken` flags:
32+
33+
Example:
34+
35+
```bash
36+
go test -tags=e2e -jfrog.url=http://localhost:8082 -jfrog.adminToken=your-access-token ./e2e/...
37+
```

0 commit comments

Comments
 (0)