From 634ec386b1022726bb8785445c962a7c37a47bd2 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 31 Jan 2025 11:38:47 +0300 Subject: [PATCH 1/3] fix regionId & cityId unmarshaling error --- .github/workflows/ci.yml | 24 ++++++----- client_test.go | 90 +++++++++++++++++++++++++++++++++++++++- types.go | 7 +++- 3 files changed, 108 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84ba95f..b23710c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,10 @@ jobs: steps: - name: Check out code into the Go module directory uses: actions/checkout@v2 - - name: Set up Go 1.17 - uses: actions/setup-go@v2 + - name: Set up Go 1.23 + uses: actions/setup-go@v3 with: - go-version: '1.17' + go-version: '1.23' - name: Get dependencies run: | go mod tidy @@ -31,7 +31,7 @@ jobs: - name: Lint code with golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.50.1 + version: v1.62.2 only-new-issues: true skip-pkg-cache: true args: --build-tags=testutils @@ -40,13 +40,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: ['1.13', '1.14', '1.15', '1.16', '1.17'] + go-version: ['1.19', '1.20', '1.21', '1.22', '1.23', 'stable'] include: - - go-version: '1.17' + - go-version: '1.23' coverage: 1 steps: - name: Set up Go ${{ matrix.go-version }} - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - name: Check out code into the Go module directory @@ -59,17 +59,21 @@ jobs: env: COVERAGE: ${{ matrix.coverage }} if: env.COVERAGE != 1 - run: go test -tags=testutils ./... + run: | + go install gotest.tools/gotestsum@latest + gotestsum --format testdox ./... -tags=testutils-v -cpu 2 -timeout 60s -race - name: Tests with coverage env: COVERAGE: ${{ matrix.coverage }} if: env.COVERAGE == 1 run: | - go test -tags=testutils ./... -race -coverprofile=coverage.txt -covermode=atomic "$d" + go install gotest.tools/gotestsum@latest + gotestsum --format testdox ./... -tags=testutils-v -cpu 2 -timeout 60s -race -cover -coverprofile=coverage.txt -covermode=atomic "$d" - name: Coverage env: COVERAGE: ${{ matrix.coverage }} if: env.COVERAGE == 1 run: | + go install github.com/axw/gocov/gocov@latest + gocov convert ./coverage.txt | gocov report bash <(curl -s https://codecov.io/bash) - rm coverage.txt diff --git a/client_test.go b/client_test.go index 7f2efc0..398be36 100644 --- a/client_test.go +++ b/client_test.go @@ -3822,7 +3822,95 @@ func TestClient_PriceTypes(t *testing.T) { gock.New(crmURL). Get("/reference/price-types"). Reply(200). - BodyString(`{"success": true}`) + BodyString(` +{ + "success": true, + "priceTypes": [ + { + "id": 1, + "code": "base", + "name": "Base", + "active": true, + "promo": false, + "default": true, + "geo": [], + "groups": [], + "ordering": 1, + "currency": "MXN" + }, + { + "id": 4, + "code": "cop", + "name": "COP", + "active": false, + "promo": false, + "default": false, + "geo": [], + "groups": [ + "manager_1" + ], + "ordering": 990, + "currency": "MXN" + }, + { + "id": 2, + "code": "promo_test", + "name": "Promotional", + "active": false, + "promo": true, + "default": false, + "geo": [ + { + "country": "CO", + "regionId": "", + "region": "Todas las regiones", + "cityId": "", + "city": "All" + }, + { + "country": "ES", + "regionId": "", + "region": "Todas las regiones", + "cityId": "", + "city": "All" + }, + { + "country": "MX", + "regionId": "", + "region": "Todas las regiones", + "cityId": "", + "city": "All" + } + ], + "groups": [], + "ordering": 990, + "currency": "MXN" + }, + { + "id": 3, + "code": "wholesale", + "name": "Wholesale", + "active": false, + "promo": true, + "default": false, + "description": "Solo para ventas al mayoreo con mas de 10 articulos.", + "filterExpression": "order.quantity >= 1", + "geo": [ + { + "country": "MX", + "regionId": "", + "region": "Todas las regiones", + "cityId": "", + "city": "All" + } + ], + "groups": [], + "ordering": 990, + "currency": "MXN" + } + ] +} +`) data, st, err := c.PriceTypes() if err != nil { diff --git a/types.go b/types.go index cade78e..77e3424 100644 --- a/types.go +++ b/types.go @@ -53,13 +53,16 @@ type Address struct { Text string `json:"text,omitempty"` } +// GeoID type. Can be empty string. +type GeoID json.Number + // GeoHierarchyRow type. type GeoHierarchyRow struct { Country string `json:"country,omitempty"` Region string `json:"region,omitempty"` - RegionID int `json:"regionId,omitempty"` + RegionID GeoID `json:"regionId,omitempty"` City string `json:"city,omitempty"` - CityID int `json:"cityId,omitempty"` + CityID GeoID `json:"cityId,omitempty"` } // Source type. From 92a5741c84fd1596fad72893c7f102205e5976ba Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 31 Jan 2025 11:41:22 +0300 Subject: [PATCH 2/3] fix ci --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b23710c..fa80932 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,14 +61,14 @@ jobs: if: env.COVERAGE != 1 run: | go install gotest.tools/gotestsum@latest - gotestsum --format testdox ./... -tags=testutils-v -cpu 2 -timeout 60s -race + gotestsum --format testdox ./... -tags=testutils -v -cpu 2 -timeout 60s -race - name: Tests with coverage env: COVERAGE: ${{ matrix.coverage }} if: env.COVERAGE == 1 run: | go install gotest.tools/gotestsum@latest - gotestsum --format testdox ./... -tags=testutils-v -cpu 2 -timeout 60s -race -cover -coverprofile=coverage.txt -covermode=atomic "$d" + gotestsum --format testdox ./... -tags=testutils -v -cpu 2 -timeout 60s -race -cover -coverprofile=coverage.txt -covermode=atomic "$d" - name: Coverage env: COVERAGE: ${{ matrix.coverage }} From a482cd1a2fa00bb6adf5a6f571ee33952cc54ed2 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 31 Jan 2025 11:47:59 +0300 Subject: [PATCH 3/3] update linter config --- .golangci.yml | 58 ++++++++++++++++++++++++++------------------------ system_time.go | 2 +- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f383f9a..4aa1153 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,11 +1,37 @@ run: skip-dirs-use-default: true allow-parallel-runners: true - skip-files: + +issues: + exclude-files: - testutils.go + exclude-rules: + - path: _test\.go + linters: + - lll + - errcheck + - misspell + - ineffassign + - whitespace + - makezero + - errcheck + - funlen + - goconst + - gocognit + - gocyclo + - godot + - unused + - errchkjson + - varnamelen + exclude-use-default: true + exclude-case-sensitive: false + max-issues-per-linter: 0 + max-same-issues: 0 + fix: true output: - format: colored-line-number + formats: + - format: colored-line-number sort-results: true # Linters below do not support go1.18 yet because of generics. @@ -38,6 +64,7 @@ linters: - errorlint - exhaustive - exportloopref + - copyloopvar - funlen - gocognit - goconst @@ -53,7 +80,6 @@ linters: - nestif - prealloc - predeclared - - exportloopref - unconvert - whitespace @@ -178,34 +204,10 @@ linters-settings: - t *testing.T - e error - i int -issues: - exclude-rules: - - path: _test\.go - linters: - - lll - - errcheck - - misspell - - ineffassign - - whitespace - - makezero - - errcheck - - funlen - - goconst - - gocognit - - gocyclo - - godot - - unused - - errchkjson - - varnamelen - exclude-use-default: true - exclude-case-sensitive: false - max-issues-per-linter: 0 - max-same-issues: 0 - fix: true severity: default-severity: error case-sensitive: false service: - golangci-lint-version: 1.50.x + golangci-lint-version: 1.62.x diff --git a/system_time.go b/system_time.go index dde62ec..4fa967d 100644 --- a/system_time.go +++ b/system_time.go @@ -23,7 +23,7 @@ func (st SystemTime) MarshalJSON() ([]byte, error) { return []byte(st.String()), nil } -// String returns the time in the custom format +// String returns the time in the custom format. func (st *SystemTime) String() string { t := time.Time(*st) return fmt.Sprintf("%q", t.Format(systemTimeLayout))