Skip to content

Commit b84c70a

Browse files
authored
[TT-15967] add alias packages (#7520)
### **User description** <!-- Provide a general summary of your changes in the Title above --> - Use alias package to export symbols to be used from this repository. - After this is done, repositories importing tyk gateway packages (except allowed ones) would be guarded with linter checks. This could be helpful while automating dashboard <-> gateway coupled API tests, and run them only when the allowed packages are changed. - Upgraded mockgen from v0.4.0 to v0.6.0 to resolve an issue where the `-imports` flag was not being respected in generated mocks - this ensures that devX stays the same. https://tyktech.atlassian.net/browse/TT-15967 <!-- Why is this change required? What problem does it solve? --> <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why <!---TykTechnologies/jira-linter starts here--> <details> <summary> <a href="https://tyktech.atlassian.net/browse/TT-15967" title="TT-15967" target="_blank">TT-15967</a> </summary> | | | |---------|----| | Status | In Code Review | | Summary | Remove direct package imports from Tyk Gateway, keep only selected packages | Generated at: 2025-11-04 07:49:31 </details> <!---TykTechnologies/jira-linter ends here--> <!-- Provide a general summary of your changes in the Title above --> ## Description <!-- Describe your changes in detail --> ## Related Issue <!-- This project only accepts pull requests related to open issues. --> <!-- If suggesting a new feature or change, please discuss it in an issue first. --> <!-- If fixing a bug, there should be an issue describing it with steps to reproduce. --> <!-- OSS: Please link to the issue here. Tyk: please create/link the JIRA ticket. --> ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ### **PR Type** Enhancement, Tests, Configuration ___ ### **Description** - Introduce alias export packages - Regenerate gomock with typed params - Rename CI lint job and dependencies - Improve SonarCloud PR analysis args ___ ### Diagram Walkthrough ```mermaid flowchart LR alias["Alias packages under pkg/alias"] -- "expose selected symbols" --> consumers["Downstream consumers"] mocks["Regenerated gomock mocks"] -- "typed params + isgomock marker" --> tests["More robust tests"] ci["CI workflow updates"] -- "lint job rename, deps" --> jobs["Test and Sonar depend on lint"] sonar["SonarCloud step"] -- "dynamic PR args" --> analysis["Accurate PR analysis"] ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Tests</strong></td><td><details><summary>5 files</summary><table> <tr> <td><strong>mock.go</strong><dd><code>Regenerate certificate manager gomock with typed args</code>&nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7520/files#diff-75a25b7d4ff1829eb0c62d758828c98183e4d85e97db052db893e99054232370">+33/-32</a>&nbsp; </td> </tr> <tr> <td><strong>batcher_mock.go</strong><dd><code>Add isgomock and name parameters in mocks</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7520/files#diff-f060a65a8e827b3787a3d9a46b172e839bd3db0fbb328b111ec8245981736675">+14/-12</a>&nbsp; </td> </tr> <tr> <td><strong>cache_mock.go</strong><dd><code>Use descriptive param names in cooldown cache mocks</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7520/files#diff-a2c546883935af1b52620785f3531b1f1ad449de9e2f517f39e53da26b67e56e">+25/-24</a>&nbsp; </td> </tr> <tr> <td><strong>engine_mock_test.go</strong><dd><code>Refine GraphQL engine mocks with named params</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7520/files#diff-a867d75607ee7d81cb71edd40179ce8a58f6d4b60066384b28291b7fb789efed">+37/-32</a>&nbsp; </td> </tr> <tr> <td><strong>storage.go</strong><dd><code>Update rolling window mocks with named params</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7520/files#diff-0e75f439d0385d9272ea3afa9fc465dcae08554f19ff821e0743ad096325df40">+9/-8</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Enhancement</strong></td><td><details><summary>2 files</summary><table> <tr> <td><strong>crypto.go</strong><dd><code>New crypto alias exposing HashStr</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7520/files#diff-b01f093e8c71d25116ca9527e7f4207f50e0ef48317ec89923cdc6ed84184193">+7/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>gateway.go</strong><dd><code>New gateway alias re-exporting events and test utils</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7520/files#diff-6c487d395487597b2aca27e8848025e410dd24b71734cd904b2e535b14a68a45">+29/-0</a>&nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Configuration changes</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>ci-tests.yml</strong><dd><code>Rename lint job and add dynamic SonarCloud PR args</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7520/files#diff-03609cb60b0c6e92fb771eb8787d6722b8c31ca4c03eabc788e147acd8c6fb43">+31/-13</a>&nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Dependencies</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>deps.yml</strong><dd><code>Upgrade mockgen to v0.6.0</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7520/files#diff-dd52559dac2636b84a787d78b08a48fb92258a5f586f097fd727941bd927d4b7">+1/-1</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></details></td></tr></tr></tbody></table> </details> ___
1 parent fe0d4fd commit b84c70a

9 files changed

Lines changed: 186 additions & 122 deletions

File tree

.github/workflows/ci-tests.yml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ env:
2727
BRANCH_NAME: ${{ github.base_ref || github.ref_name }} # base_ref for PRs is 'master', but merges read in ref_name
2828

2929
jobs:
30-
golangci-lint:
30+
lint:
3131
runs-on: ubuntu-latest
3232
if: ${{ !github.event.pull_request.draft }}
3333
steps:
@@ -86,7 +86,7 @@ jobs:
8686
test:
8787
name: Go ${{ matrix.go-version }} Redis ${{ matrix.redis-version }}
8888
if: ${{ !github.event.pull_request.draft }}
89-
needs: golangci-lint
89+
needs: lint
9090
# Runs on is pinned to a version that provides python 3.10.
9191
# See: https://github.com/actions/runner-images?tab=readme-ov-file#available-images
9292
# Avoid using ubuntu-latest as it would upgrade python unattended.
@@ -177,7 +177,7 @@ jobs:
177177
sonar-cloud-analysis:
178178
runs-on: ubuntu-latest
179179
if: ${{ !github.event.pull_request.draft }}
180-
needs: [test, golangci-lint]
180+
needs: [test, lint]
181181
steps:
182182
- name: "Checkout repository"
183183
uses: TykTechnologies/github-actions/.github/actions/checkout-pr@main
@@ -201,20 +201,38 @@ jobs:
201201
files: 'gateway-all.cov, golangci-lint-report.json'
202202
fail: true
203203

204+
- name: Set SonarCloud parameters
205+
id: sonar_params
206+
run: |
207+
# Common parameters for both PR and push
208+
SONAR_ARGS="-Dsonar.organization=tyktechnologies \
209+
-Dsonar.projectKey=TykTechnologies_tyk \
210+
-Dsonar.sources=. \
211+
-Dsonar.exclusions=**/testdata/*,test/**,tests/**,coprocess/**/*,ci/**,templates/**,**/*.pb.go,internal/graphengine/gomock_reflect_3503306920/* \
212+
-Dsonar.coverage.exclusions=**/*_test.go,**/*_mock.go,**/mock/*,tests/**,swagger*.yml,**/*.pb.go,internal/graphengine/gomock_reflect_3503306920/* \
213+
-Dsonar.test.inclusions=**/*_test.go,tests/** \
214+
-Dsonar.tests=. \
215+
-Dsonar.go.coverage.reportPaths=gateway-all.cov \
216+
-Dsonar.go.golangci-lint.reportPaths=golangci-lint-report.json"
217+
218+
# Add PR-specific parameters if this is a pull request
219+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
220+
SONAR_ARGS="$SONAR_ARGS \
221+
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
222+
-Dsonar.pullrequest.branch=${{ github.head_ref }} \
223+
-Dsonar.pullrequest.base=${{ github.base_ref }}"
224+
echo "Running SonarCloud in pull request mode"
225+
else
226+
echo "Running SonarCloud in full analysis mode"
227+
fi
228+
229+
echo "sonar_args=$SONAR_ARGS" >> $GITHUB_OUTPUT
230+
204231
- name: Scan
205232
if: always()
206233
uses: sonarsource/sonarqube-scan-action@master
207234
with:
208-
args: >
209-
-Dsonar.organization=tyktechnologies
210-
-Dsonar.projectKey=TykTechnologies_tyk
211-
-Dsonar.sources=.
212-
-Dsonar.exclusions=**/testdata/*,test/**,tests/**,coprocess/**/*,ci/**,templates/**,**/*.pb.go,internal/graphengine/gomock_reflect_3503306920/*
213-
-Dsonar.coverage.exclusions=**/*_test.go,**/mock/*,tests/**,swagger*.yml,**/*.pb.go,internal/graphengine/gomock_reflect_3503306920/*
214-
-Dsonar.test.inclusions=**/*_test.go,tests/**
215-
-Dsonar.tests=.
216-
-Dsonar.go.coverage.reportPaths=gateway-all.cov
217-
-Dsonar.go.golangci-lint.reportPaths=golangci-lint-report.json
235+
args: ${{ steps.sonar_params.outputs.sonar_args }}
218236
env:
219237
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
220238
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.taskfiles/deps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tasks:
2121
status:
2222
- type mockgen
2323
cmds:
24-
- go install go.uber.org/mock/mockgen@v0.4.0
24+
- go install go.uber.org/mock/mockgen@v0.6.0
2525

2626
gotestsum:
2727
internal: true

certs/mock/mock.go

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

internal/certcheck/batcher_mock.go

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

0 commit comments

Comments
 (0)