Skip to content

Commit 4fb4a89

Browse files
committed
Added tests
1 parent a5a2b92 commit 4fb4a89

25 files changed

+691
-208
lines changed

.github/workflows/analysis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
with:
1919
go-version-file: go.mod
2020

21+
- name: Generate Mocks
22+
run: make generate-mock
23+
2124
- name: Static Code Analysis
2225
uses: golangci/golangci-lint-action@v6
2326
with:

.github/workflows/tests.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ jobs:
3333
restore-keys: go-
3434

3535
- name: Run Tests
36-
env:
37-
XUNIT_OUTFILE: test-reports/unit.xml
3836
run: |
39-
test -d "$(dirname $XUNIT_OUTFILE)" || mkdir -p "$(dirname $XUNIT_OUTFILE)"
40-
.github/scripts/gotest.sh ./...
37+
make test-ci
4138
4239
- name: Publish Results
4340
uses: EnricoMi/publish-unit-test-result-action@v2
4441
if: always()
4542
with:
4643
check_name: Unit Tests Results
4744
files: |
48-
test-reports/unit.xml
45+
utests-report.xml

.golangci.yml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
# Options for analysis running
22
# More info could be found at https://golangci-lint.run/usage/configuration/
33
run:
4-
# timeout for analysis, e.g. 30s, 5m, default is 1m
5-
timeout: 5m
6-
modules-download-mode: readonly
4+
# timeout for analysis, e.g. 30s, 5m, default is 1m
5+
timeout: 5m
6+
modules-download-mode: readonly
77

88
# List of useful linters could be found at https://github.com/golangci/awesome-go-linters
99
linters:
10-
disable-all: true
11-
enable:
12-
- errcheck
13-
- copyloopvar
14-
- gofumpt
15-
- goimports
16-
- gosimple
17-
- govet
18-
- ineffassign
19-
- makezero
20-
- misspell
21-
- noctx
22-
- nolintlint
23-
- rowserrcheck
24-
- sqlclosecheck
25-
- staticcheck
26-
- unconvert
27-
- unused
28-
- wastedassign
29-
- gosec
10+
disable-all: true
11+
enable:
12+
- errcheck
13+
- copyloopvar
14+
- gofumpt
15+
- goimports
16+
- gosimple
17+
- govet
18+
- ineffassign
19+
- makezero
20+
- misspell
21+
- noctx
22+
- nolintlint
23+
- rowserrcheck
24+
- sqlclosecheck
25+
- staticcheck
26+
- unconvert
27+
- unused
28+
- wastedassign
29+
- gosec
3030

3131
linters-settings:
32-
staticcheck:
33-
# https://staticcheck.io/docs/options#checks
34-
checks: [ "all","-SA1019","-SA1029" ]
35-
gosec:
36-
excludes: ["G204", "G301", "G302", "G304", "G306", "G601", "G101", "G407"]
37-
exclude-generated: true
38-
exclude-test-files: true
39-
config:
40-
global:
41-
nosec: true
32+
staticcheck:
33+
# https://staticcheck.io/docs/options#checks
34+
checks: [ "all","-SA1019","-SA1029" ]
35+
gosec:
36+
excludes: [ "G204", "G301", "G302", "G304", "G306", "G601", "G101", "G407" ]
37+
exclude-generated: true
38+
exclude-test-files: true
39+
config:
40+
global:
41+
nosec: true
4242

4343
issues:
44-
exclude-use-default: false
45-
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
46-
max-issues-per-linter: 0
47-
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
48-
max-same-issues: 0
44+
exclude-use-default: false
45+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
46+
max-issues-per-linter: 0
47+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
48+
max-same-issues: 0

Makefile

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export PROJECT_DIR ?= $(CURDIR)
55
BINARY_CLI = bin
66
WORKSPACE_ROOT = $(shell cd "${PROJECT_DIR}" && pwd)
77
TOOLS_DIR := $(CURDIR)/.tools
8-
SCRIPTS_DIR = ${PROJECT_DIR}/.github/scripts
8+
SCRIPTS_DIR = ${PROJECT_DIR}/scripts
99
TARGET_DIR = ${PROJECT_DIR}/target
1010
LINKERFLAGS = -s -w
1111
COMPILERFLAGS = all=-trimpath=$(WORKSPACE_ROOT)
@@ -34,7 +34,7 @@ GOIMPORTS:
3434
########## ANALYSE ##########
3535

3636
GOLANGCI_LINT = ${TOOLS_DIR}/golangci-lint
37-
GOLANGCI_LINT_VERSION = 1.62.2
37+
GOLANGCI_LINT_VERSION = 1.63.4
3838

3939
verify: GOLANGCI_LINT
4040
echo $(GO_SOURCES)
@@ -45,8 +45,9 @@ GOLANGCI_LINT:
4545

4646
########## BUILD ##########
4747
prereq::
48-
$(GOCMD) install github.com/jstemmer/go-junit-report@v1.0.0
48+
$(GOCMD) install github.com/jstemmer/go-junit-report/v2@latest
4949
GOBIN=${TOOLS_DIR} $(GOCMD) install go.uber.org/mock/[email protected]
50+
${TOOLS_DIR}/mockgen --version
5051

5152
build::
5253
$(GOCMD) env GOOS GOARCH
@@ -63,26 +64,23 @@ build-install:: build
6364
.PHONY: clean-mock
6465
clean-mock:
6566
@echo Cleaning generated mock files
66-
find . -path "*/mocks/*.go" -delete
67+
@find . -name "*_mock.go" -delete
68+
69+
.PHONY: clean
70+
clean:: clean-mock
71+
@echo Cleaning generated files
72+
@rm -rf ${BINARY_CLI}
6773

6874
.PHONY: generate-mock
69-
generate-mock: clean-mock
75+
generate-mock: prereq clean-mock
7076
@echo Generating test mocks
7177
TOOLS_DIR=$(TOOLS_DIR) go generate ./...
7278

73-
test-prereq: prereq generate-mock
74-
mkdir -p target/reports
79+
test-prereq: generate-mock
7580

7681
test: PACKAGES=./...
77-
test: TEST_ARGS=-short
78-
test: test-prereq do-run-tests
79-
80-
itest: PACKAGES=./test/...
81-
itest: TAGS=-tags=itest
82-
itest: TEST_ARGS=-count=1 -p=1
83-
itest:: test-prereq do-run-tests
84-
85-
do-run-tests::
86-
$(SCRIPTS_DIR)/gotest.sh $$(go list $(TAGS) $(PACKAGES) | grep -v "^.*/mocks$$") -timeout 30m -coverpkg=github.com/jfrog/jfrog-cli-application/... -coverprofile=$(TARGET_DIR)/reports/coverage.out $(TEST_ARGS) $(TAGS)
82+
test: test-prereq
83+
go test ./...
84+
test-ci: test-prereq
85+
go test -v 2>&1 ./... | go-junit-report -set-exit-code -iocopy -out utests-report.xml
8786

88-
.PHONY: $(MAKECMDGOALS)

application/app/auth/app_details.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

application/app/context.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
package app
22

33
import (
4-
"github.com/jfrog/jfrog-cli-application/application/service"
4+
"github.com/jfrog/jfrog-cli-application/application/service/systems"
5+
"github.com/jfrog/jfrog-cli-application/application/service/versions"
56
)
67

78
type Context interface {
8-
GetVersionService() service.VersionService
9-
GetSystemService() service.SystemService
9+
GetVersionService() versions.VersionService
10+
GetSystemService() systems.SystemService
1011
GetConfig() interface{}
1112
}
1213

1314
type context struct {
14-
versionService service.VersionService
15-
systemService service.SystemService
15+
versionService versions.VersionService
16+
systemService systems.SystemService
1617
}
1718

1819
func NewAppContext() Context {
1920
return &context{
20-
versionService: service.NewVersionService(),
21-
systemService: service.NewSystemService(),
21+
versionService: versions.NewVersionService(),
22+
systemService: systems.NewSystemService(),
2223
}
2324
}
2425

25-
func (c *context) GetVersionService() service.VersionService {
26+
func (c *context) GetVersionService() versions.VersionService {
2627
return c.versionService
2728
}
2829

29-
func (c *context) GetSystemService() service.SystemService {
30+
func (c *context) GetSystemService() systems.SystemService {
3031
return c.systemService
3132
}
3233

application/app/context_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package app
2+
3+
import (
4+
"testing"
5+
6+
mocksystems "github.com/jfrog/jfrog-cli-application/application/service/systems/mocks"
7+
mockversions "github.com/jfrog/jfrog-cli-application/application/service/versions/mocks"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestNewAppContext(t *testing.T) {
13+
ctx := NewAppContext()
14+
assert.NotNil(t, ctx)
15+
assert.NotNil(t, ctx.GetVersionService())
16+
assert.NotNil(t, ctx.GetSystemService())
17+
}
18+
19+
func TestGetVersionService(t *testing.T) {
20+
mockVersionService := &mockversions.MockVersionService{}
21+
ctx := &context{
22+
versionService: mockVersionService,
23+
}
24+
assert.Equal(t, mockVersionService, ctx.GetVersionService())
25+
}
26+
27+
func TestGetSystemService(t *testing.T) {
28+
mockSystemService := &mocksystems.MockSystemService{}
29+
ctx := &context{
30+
systemService: mockSystemService,
31+
}
32+
assert.Equal(t, mockSystemService, ctx.GetSystemService())
33+
}
34+
35+
func TestGetConfig(t *testing.T) {
36+
ctx := &context{}
37+
assert.Nil(t, ctx.GetConfig())
38+
}

application/commands/system/ping_cmd.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
package system
22

3+
//go:generate ${PROJECT_DIR}/scripts/mockgen.sh ${GOFILE}
4+
35
import (
46
"github.com/jfrog/jfrog-cli-application/application/app"
57
"github.com/jfrog/jfrog-cli-application/application/commands"
68
"github.com/jfrog/jfrog-cli-application/application/commands/utils"
79
"github.com/jfrog/jfrog-cli-application/application/common"
810
"github.com/jfrog/jfrog-cli-application/application/service"
11+
"github.com/jfrog/jfrog-cli-application/application/service/systems"
912
commonCLiCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands"
1013
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
1114
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
1215
)
1316

1417
type pingCommand struct {
15-
systemService service.SystemService
18+
systemService systems.SystemService
1619
serverDetails *coreConfig.ServerDetails
1720
}
1821

1922
func (pc *pingCommand) Run() error {
20-
ctx := &service.Context{ServerDetails: pc.serverDetails}
23+
ctx, err := service.NewContext(*pc.serverDetails)
24+
if err != nil {
25+
return err
26+
}
27+
2128
return pc.systemService.Ping(ctx)
2229
}
2330

application/commands/version/create_app_version_cmd.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package version
33
import (
44
"encoding/json"
55

6+
"github.com/jfrog/jfrog-cli-application/application/service/versions"
7+
68
"github.com/jfrog/jfrog-cli-application/application/app"
79
"github.com/jfrog/jfrog-cli-application/application/commands"
810
"github.com/jfrog/jfrog-cli-application/application/commands/utils"
@@ -19,7 +21,7 @@ import (
1921
)
2022

2123
type createAppVersionCommand struct {
22-
versionService service.VersionService
24+
versionService versions.VersionService
2325
serverDetails *coreConfig.ServerDetails
2426
requestPayload *model.CreateAppVersionRequest
2527
}
@@ -29,7 +31,11 @@ type createVersionSpec struct {
2931
}
3032

3133
func (cv *createAppVersionCommand) Run() error {
32-
ctx := &service.Context{ServerDetails: cv.serverDetails}
34+
ctx, err := service.NewContext(*cv.serverDetails)
35+
if err != nil {
36+
return err
37+
}
38+
3339
return cv.versionService.CreateAppVersion(ctx, cv.requestPayload)
3440
}
3541

0 commit comments

Comments
 (0)