Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
with:
go-version-file: go.mod

- name: Generate Mocks
run: make generate-mock

- name: Static Code Analysis
uses: golangci/golangci-lint-action@v6
with:
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ jobs:
restore-keys: go-

- name: Run Tests
env:
XUNIT_OUTFILE: test-reports/unit.xml
run: |
test -d "$(dirname $XUNIT_OUTFILE)" || mkdir -p "$(dirname $XUNIT_OUTFILE)"
.github/scripts/gotest.sh ./...
make test-ci

- name: Publish Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: Unit Tests Results
files: |
test-reports/unit.xml
utests-report.xml
76 changes: 38 additions & 38 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# Options for analysis running
# More info could be found at https://golangci-lint.run/usage/configuration/
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m
modules-download-mode: readonly
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m
modules-download-mode: readonly

# List of useful linters could be found at https://github.com/golangci/awesome-go-linters
linters:
disable-all: true
enable:
- errcheck
- copyloopvar
- gofumpt
- goimports
- gosimple
- govet
- ineffassign
- makezero
- misspell
- noctx
- nolintlint
- rowserrcheck
- sqlclosecheck
- staticcheck
- unconvert
- unused
- wastedassign
- gosec
disable-all: true
enable:
- errcheck
- copyloopvar
- gofumpt
- goimports
- gosimple
- govet
- ineffassign
- makezero
- misspell
- noctx
- nolintlint
- rowserrcheck
- sqlclosecheck
- staticcheck
- unconvert
- unused
- wastedassign
- gosec

linters-settings:
staticcheck:
# https://staticcheck.io/docs/options#checks
checks: [ "all","-SA1019","-SA1029" ]
gosec:
excludes: ["G204", "G301", "G302", "G304", "G306", "G601", "G101", "G407"]
exclude-generated: true
exclude-test-files: true
config:
global:
nosec: true
staticcheck:
# https://staticcheck.io/docs/options#checks
checks: [ "all","-SA1019","-SA1029" ]
gosec:
excludes: [ "G204", "G301", "G302", "G304", "G306", "G601", "G101", "G407" ]
exclude-generated: true
exclude-test-files: true
config:
global:
nosec: true

issues:
exclude-use-default: false
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
exclude-use-default: false
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
34 changes: 16 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export PROJECT_DIR ?= $(CURDIR)
BINARY_CLI = bin
WORKSPACE_ROOT = $(shell cd "${PROJECT_DIR}" && pwd)
TOOLS_DIR := $(CURDIR)/.tools
SCRIPTS_DIR = ${PROJECT_DIR}/.github/scripts
SCRIPTS_DIR = ${PROJECT_DIR}/scripts
TARGET_DIR = ${PROJECT_DIR}/target
LINKERFLAGS = -s -w
COMPILERFLAGS = all=-trimpath=$(WORKSPACE_ROOT)
Expand Down Expand Up @@ -34,7 +34,7 @@ GOIMPORTS:
########## ANALYSE ##########

GOLANGCI_LINT = ${TOOLS_DIR}/golangci-lint
GOLANGCI_LINT_VERSION = 1.62.2
GOLANGCI_LINT_VERSION = 1.63.4

verify: GOLANGCI_LINT
echo $(GO_SOURCES)
Expand All @@ -45,8 +45,9 @@ GOLANGCI_LINT:

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

build::
$(GOCMD) env GOOS GOARCH
Expand All @@ -63,26 +64,23 @@ build-install:: build
.PHONY: clean-mock
clean-mock:
@echo Cleaning generated mock files
find . -path "*/mocks/*.go" -delete
@find . -name "*_mock.go" -delete

.PHONY: clean
clean:: clean-mock
@echo Cleaning generated files
@rm -rf ${BINARY_CLI}

.PHONY: generate-mock
generate-mock: clean-mock
generate-mock: prereq clean-mock
@echo Generating test mocks
TOOLS_DIR=$(TOOLS_DIR) go generate ./...

test-prereq: prereq generate-mock
mkdir -p target/reports
test-prereq: generate-mock

test: PACKAGES=./...
test: TEST_ARGS=-short
test: test-prereq do-run-tests

itest: PACKAGES=./test/...
itest: TAGS=-tags=itest
itest: TEST_ARGS=-count=1 -p=1
itest:: test-prereq do-run-tests

do-run-tests::
$(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)
test: test-prereq
go test ./...
test-ci: test-prereq
go test -v 2>&1 ./... | go-junit-report -set-exit-code -iocopy -out utests-report.xml

.PHONY: $(MAKECMDGOALS)
15 changes: 0 additions & 15 deletions application/app/auth/app_details.go

This file was deleted.

19 changes: 10 additions & 9 deletions application/app/context.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
package app

import (
"github.com/jfrog/jfrog-cli-application/application/service"
"github.com/jfrog/jfrog-cli-application/application/service/systems"
"github.com/jfrog/jfrog-cli-application/application/service/versions"
)

type Context interface {
GetVersionService() service.VersionService
GetSystemService() service.SystemService
GetVersionService() versions.VersionService
GetSystemService() systems.SystemService
GetConfig() interface{}
}

type context struct {
versionService service.VersionService
systemService service.SystemService
versionService versions.VersionService
systemService systems.SystemService
}

func NewAppContext() Context {
return &context{
versionService: service.NewVersionService(),
systemService: service.NewSystemService(),
versionService: versions.NewVersionService(),
systemService: systems.NewSystemService(),
}
}

func (c *context) GetVersionService() service.VersionService {
func (c *context) GetVersionService() versions.VersionService {
return c.versionService
}

func (c *context) GetSystemService() service.SystemService {
func (c *context) GetSystemService() systems.SystemService {
return c.systemService
}

Expand Down
38 changes: 38 additions & 0 deletions application/app/context_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package app

import (
"testing"

mocksystems "github.com/jfrog/jfrog-cli-application/application/service/systems/mocks"
mockversions "github.com/jfrog/jfrog-cli-application/application/service/versions/mocks"

"github.com/stretchr/testify/assert"
)

func TestNewAppContext(t *testing.T) {
ctx := NewAppContext()
assert.NotNil(t, ctx)
assert.NotNil(t, ctx.GetVersionService())
assert.NotNil(t, ctx.GetSystemService())
}

func TestGetVersionService(t *testing.T) {
mockVersionService := &mockversions.MockVersionService{}
ctx := &context{
versionService: mockVersionService,
}
assert.Equal(t, mockVersionService, ctx.GetVersionService())
}

func TestGetSystemService(t *testing.T) {
mockSystemService := &mocksystems.MockSystemService{}
ctx := &context{
systemService: mockSystemService,
}
assert.Equal(t, mockSystemService, ctx.GetSystemService())
}

func TestGetConfig(t *testing.T) {
ctx := &context{}
assert.Nil(t, ctx.GetConfig())
}
11 changes: 9 additions & 2 deletions application/commands/system/ping_cmd.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package system

//go:generate ${PROJECT_DIR}/scripts/mockgen.sh ${GOFILE}

import (
"github.com/jfrog/jfrog-cli-application/application/app"
"github.com/jfrog/jfrog-cli-application/application/commands"
"github.com/jfrog/jfrog-cli-application/application/commands/utils"
"github.com/jfrog/jfrog-cli-application/application/common"
"github.com/jfrog/jfrog-cli-application/application/service"
"github.com/jfrog/jfrog-cli-application/application/service/systems"
commonCLiCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands"
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
)

type pingCommand struct {
systemService service.SystemService
systemService systems.SystemService
serverDetails *coreConfig.ServerDetails
}

func (pc *pingCommand) Run() error {
ctx := &service.Context{ServerDetails: pc.serverDetails}
ctx, err := service.NewContext(*pc.serverDetails)
if err != nil {
return err
}

return pc.systemService.Ping(ctx)
}

Expand Down
10 changes: 8 additions & 2 deletions application/commands/version/create_app_version_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package version
import (
"encoding/json"

"github.com/jfrog/jfrog-cli-application/application/service/versions"

"github.com/jfrog/jfrog-cli-application/application/app"
"github.com/jfrog/jfrog-cli-application/application/commands"
"github.com/jfrog/jfrog-cli-application/application/commands/utils"
Expand All @@ -19,7 +21,7 @@ import (
)

type createAppVersionCommand struct {
versionService service.VersionService
versionService versions.VersionService
serverDetails *coreConfig.ServerDetails
requestPayload *model.CreateAppVersionRequest
}
Expand All @@ -29,7 +31,11 @@ type createVersionSpec struct {
}

func (cv *createAppVersionCommand) Run() error {
ctx := &service.Context{ServerDetails: cv.serverDetails}
ctx, err := service.NewContext(*cv.serverDetails)
if err != nil {
return err
}

return cv.versionService.CreateAppVersion(ctx, cv.requestPayload)
}

Expand Down
Loading
Loading