From 78c696ae268e8917e7815ce5a0b0ab8870e81f93 Mon Sep 17 00:00:00 2001 From: elliotxx <951376975@qq.com> Date: Fri, 3 Jan 2025 23:11:19 +0800 Subject: [PATCH 1/3] refactor: replace direct 'go' command with '$(GO)' variable - Update Makefile and go.mk to use '$(GO)' instead of 'go' - This change allows for easier Go version management and flexibility - Affects build, test, lint, and other Go-related commands Using a variable for the Go command simplifies version management and ensures consistency across different environments. --- Makefile | 28 ++++++++++++++-------------- go.mk | 15 +++++++++------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 4ed3e0cd..2df8e28d 100644 --- a/Makefile +++ b/Makefile @@ -35,12 +35,12 @@ endif .PHONY: gen-version gen-version: ## Generate version file @echo "šŸ› ļø Updating the version file ..." - @cd pkg/version/scripts && go run gen/gen.go + @cd pkg/version/scripts && $(GO) run gen/gen.go .PHONY: test test: ## Run the tests @PKG_LIST=$${TARGET_PKG:-$(GOSOURCE_PATHS)}; \ - go test -gcflags=all=-l -timeout=10m `go list -e $${PKG_LIST} | grep -vE "cmd|internal|internalimport|generated|handler|middleware|registry|openapi|apis|version|gitutil|server|elasticsearch"` ${TEST_FLAGS} + $(GO) test -gcflags=all=-l -timeout=10m `$(GO) list -e $${PKG_LIST} | grep -vE "cmd|internal|internalimport|generated|handler|middleware|registry|openapi|apis|version|gitutil|server|elasticsearch"` ${TEST_FLAGS} # cover: Generates a coverage report for the specified TARGET_PKG or default GOSOURCE_PATHS. @@ -53,14 +53,14 @@ test: ## Run the tests cover: ## Generates coverage report @PKG_LIST=$${TARGET_PKG:-$(GOSOURCE_PATHS)}; \ echo "šŸš€ Executing unit tests for $${PKG_LIST}:"; \ - go test -gcflags=all=-l -timeout=10m `go list $${PKG_LIST} | grep -vE "cmd|internal|internalimport|generated|handler|middleware|registry|openapi|apis|version|gitutil|server|elasticsearch"` -coverprofile $(COVERAGEOUT) ${TEST_FLAGS} && \ - (echo "\nšŸ“Š Calculating coverage rate:"; go tool cover -func=$(COVERAGEOUT)) || (echo "\nšŸ’„ Running go test failed!"; exit 1) + $(GO) test -gcflags=all=-l -timeout=10m `$(GO) list $${PKG_LIST} | grep -vE "cmd|internal|internalimport|generated|handler|middleware|registry|openapi|apis|version|gitutil|server|elasticsearch"` -coverprofile $(COVERAGEOUT) ${TEST_FLAGS} && \ + (echo "\nšŸ“Š Calculating coverage rate:"; $(GO) tool cover -func=$(COVERAGEOUT)) || (echo "\nšŸ’„ Running go test failed!"; exit 1) .PHONY: format format: ## Format source code of frontend and backend - @which $(GOFORMATER) > /dev/null || (echo "Installing $(GOFORMATER)@$(GOFORMATER_VERSION) ..."; go install mvdan.cc/gofumpt@$(GOFORMATER_VERSION) && echo -e "Installation complete!\n") - @for path in $(GOSOURCE_PATHS); do ${GOFORMATER} -l -w -e `echo $${path} | cut -b 3- | rev | cut -b 5- | rev`; done; + @which $(GOFORMATER) > /dev/null || (echo "Installing $(GOFORMATER)@$(GOFORMATER_VERSION) ..."; $(GO) install mvdan.cc/gofumpt@$(GOFORMATER_VERSION) && echo -e "Installation complete!\n") + @for path in $(GOSOURCE_PATHS); do $(GOFORMATER) -l -w -e `echo $${path} | cut -b 3- | rev | cut -b 5- | rev`; done; @which $(UIFORMATER) > /dev/null || (echo "Installing $(UIFORMATER) ..."; npm install -g prettier && echo -e "Installation complete!\n") @cd ui && npx prettier --write . @@ -93,7 +93,7 @@ build-darwin: gen-version $(BUILD_UI) ## Build for MacOS (Darwin) @rm -rf ./_build/darwin @echo "šŸš€ Building karpor-server for darwin platform ..." GOOS=darwin GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \ - go build -o ./_build/darwin/$(APPROOT) \ + $(GO) build -o ./_build/darwin/$(APPROOT) \ ./cmd/karpor # Target: build-linux @@ -109,7 +109,7 @@ build-linux: gen-version $(BUILD_UI) ## Build for Linux @rm -rf ./_build/linux @echo "šŸš€ Building karpor-server for linux platform ..." GOOS=linux GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \ - go build -o ./_build/linux/$(APPROOT) \ + $(GO) build -o ./_build/linux/$(APPROOT) \ ./cmd/karpor # Target: build-windows @@ -125,7 +125,7 @@ build-windows: gen-version $(BUILD_UI) ## Build for Windows @rm -rf ./_build/windows @echo "šŸš€ Building karpor-server for windows platform ..." GOOS=windows GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \ - go build -o ./_build/windows/$(APPROOT).exe \ + $(GO) build -o ./_build/windows/$(APPROOT).exe \ ./cmd/karpor # Target: build-ui @@ -138,17 +138,17 @@ build-ui: gen-version ## Build UI for the dashboard .PHONY: check-license check-license: ## Checks if repo files contain valid license header - @which $(LICENSE_CHECKER) > /dev/null || (echo "Installing $(LICENSE_CHECKER)@$(LICENSE_CHECKER_VERSION) ..."; go install github.com/apache/skywalking-eyes/cmd/$(LICENSE_CHECKER)@$(LICENSE_CHECKER_VERSION) && echo -e "Installation complete!\n") + @which $(LICENSE_CHECKER) > /dev/null || (echo "Installing $(LICENSE_CHECKER)@$(LICENSE_CHECKER_VERSION) ..."; $(GO) install github.com/apache/skywalking-eyes/cmd/$(LICENSE_CHECKER)@$(LICENSE_CHECKER_VERSION) && echo -e "Installation complete!\n") @${GOPATH}/bin/$(LICENSE_CHECKER) header check .PHONY: fix-license fix-license: ## Adds missing license header to repo files - @which $(LICENSE_CHECKER) > /dev/null || (echo "Installing $(LICENSE_CHECKER)@$(LICENSE_CHECKER_VERSION) ..."; go install github.com/apache/skywalking-eyes/cmd/$(LICENSE_CHECKER)@$(LICENSE_CHECKER_VERSION) && echo -e "Installation complete!\n") + @which $(LICENSE_CHECKER) > /dev/null || (echo "Installing $(LICENSE_CHECKER)@$(LICENSE_CHECKER_VERSION) ..."; $(GO) install github.com/apache/skywalking-eyes/cmd/$(LICENSE_CHECKER)@$(LICENSE_CHECKER_VERSION) && echo -e "Installation complete!\n") @${GOPATH}/bin/$(LICENSE_CHECKER) header fix .PHONY: gen-api-spec gen-api-spec: ## Generate API Specification with OpenAPI format - @which swag > /dev/null || (echo "Installing swag@v1.7.8 ..."; go install github.com/swaggo/swag/cmd/swag@v1.7.8 && echo "Installation complete!\n") + @which swag > /dev/null || (echo "Installing swag@v1.7.8 ..."; $(GO) install github.com/swaggo/swag/cmd/swag@v1.7.8 && echo "Installation complete!\n") # Generate API documentation with OpenAPI format @swag init --parseDependency --parseInternal --parseDepth 1 -g cmd/karpor/main.go -o api/openapispec/ && echo "šŸŽ‰ Done!" || (echo "šŸ’„ Fail!"; exit 1) # Format swagger comments @@ -156,12 +156,12 @@ gen-api-spec: ## Generate API Specification with OpenAPI format .PHONY: gen-api-doc gen-api-doc: gen-api-spec ## Generate API Documentation by API Specification - @which swagger > /dev/null || (echo "Installing swagger@v0.30.5 ..."; go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5 && echo "Installation complete!\n") + @which swagger > /dev/null || (echo "Installing swagger@v0.30.5 ..."; $(GO) install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5 && echo "Installation complete!\n") @swagger generate markdown -f ./api/openapispec/swagger.json --output=docs/api.md && echo "šŸŽ‰ Done!" || (echo "šŸ’„ Fail!"; exit 1) .PHONY: gen-cli-doc gen-cli-doc: ## Generate CLI Documentation - @go run ./hack/gen-cli-docs/main.go && echo "šŸŽ‰ Done!" + @$(GO) run ./hack/gen-cli-docs/main.go && echo "šŸŽ‰ Done!" # Target: add-contributor # Description: Adds a new contributor to the project's list of contributors using the all-contributors-cli tool. diff --git a/go.mk b/go.mk index 3debb2d7..64bf4285 100644 --- a/go.mk +++ b/go.mk @@ -1,9 +1,12 @@ # go.mk is a Go project general Makefile, encapsulated some common Target. # Project repository: https://github.com/elliotxx/go-makefile +# Define GO command with a default value that can be overridden. e.g. GO ?= go1.22.6 +GO ?= go + APPROOT ?= $(shell basename $(PWD)) -GOPKG ?= $(shell go list 2>/dev/null) -GOPKGS ?= $(shell go list ./... 2>/dev/null) +GOPKG ?= $(shell $(GO) list 2>/dev/null) +GOPKGS ?= $(shell $(GO) list ./... 2>/dev/null) GOSOURCES ?= $(shell find . -type f -name '*.go' ! -path '*Godeps/_workspace*') # You can also customize GOSOURCE_PATHS, e.g. ./pkg/... ./cmd/... GOSOURCE_PATHS ?= ././... @@ -28,19 +31,19 @@ help: ## This help message :) .PHONY: cover-html cover-html: ## Generates coverage report and displays it in the browser - go tool cover -html=$(COVERAGEOUT) + $(GO) tool cover -html=$(COVERAGEOUT) .PHONY: lint lint: ## Lint, will not fix but sets exit code on error - @which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") + @which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") $(GOLINTER) run $(GOSOURCE_PATHS) --fast --verbose --print-resources-usage .PHONY: lint-fix lint-fix: ## Lint, will try to fix errors and modify code - @which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") + @which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") $(GOLINTER) run $(GOSOURCE_PATHS) --fix .PHONY: doc doc: ## Start the documentation server with godoc - @which godoc > /dev/null || (echo "Installing godoc@latest ..."; go install golang.org/x/tools/cmd/godoc@latest && echo -e "Installation complete!\n") + @which godoc > /dev/null || (echo "Installing godoc@latest ..."; $(GO) install golang.org/x/tools/cmd/godoc@latest && echo -e "Installation complete!\n") godoc -http=:6060 From 3779d339eb60585ee890cb7b177aa38560bc68dc Mon Sep 17 00:00:00 2001 From: elliotxx <951376975@qq.com> Date: Fri, 3 Jan 2025 23:42:49 +0800 Subject: [PATCH 2/3] chore: bump github.com/bytedance/mockey to v1.2.13 - Update github.com/bytedance/mockey to v1.2.13 - Update github.com/gopherjs/gopherjs to v1.17.2 - Update github.com/smartystreets/assertions to v1.16.0 - Update github.com/smartystreets/goconvey to v1.8.1 - Update golang.org/x/arch to v0.12.0 - Update golang.org/x/sys to v0.28.0 These updates ensure compatibility and security improvements. test: ensure proper cleanup of mocks in certgenerator tests - Add `mockey.UnPatchAll()` at the start of each test case - Ensure mocks are properly cleaned up after each test This change prevents mock interference between test cases, improving test reliability. --- go.mod | 12 ++++---- go.sum | 25 ++++++++-------- pkg/util/certgenerator/generator_test.go | 36 ++++++++++++++++++------ 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index 09e68d98..7d903b7f 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22 require ( github.com/Masterminds/sprig/v3 v3.2.2 - github.com/bytedance/mockey v1.2.10 + github.com/bytedance/mockey v1.2.13 github.com/dominikbraun/graph v0.23.0 github.com/elastic/go-elasticsearch/v8 v8.7.0 github.com/elliotxx/esquery v0.2.0-alpha.1 @@ -98,7 +98,7 @@ require ( github.com/google/cel-go v0.12.6 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect github.com/google/go-cmp v0.5.9 // indirect - github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect + github.com/gopherjs/gopherjs v1.17.2 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect github.com/huandu/xstrings v1.3.2 // indirect @@ -128,8 +128,8 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shopspring/decimal v1.2.0 // indirect github.com/sirupsen/logrus v1.9.0 // indirect - github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect - github.com/smartystreets/goconvey v1.6.4 // indirect + github.com/smarty/assertions v1.16.0 // indirect + github.com/smartystreets/goconvey v1.8.1 // indirect github.com/spf13/cast v1.3.1 // indirect github.com/stoewer/go-strcase v1.2.0 // indirect github.com/stretchr/objx v0.5.0 // indirect @@ -150,13 +150,13 @@ require ( go.opentelemetry.io/proto/otlp v0.19.0 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/arch v0.3.0 // indirect + golang.org/x/arch v0.12.0 // indirect golang.org/x/crypto v0.16.0 // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/net v0.19.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect golang.org/x/sync v0.5.0 - golang.org/x/sys v0.15.0 // indirect + golang.org/x/sys v0.28.0 // indirect golang.org/x/term v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect diff --git a/go.sum b/go.sum index 948b2fe0..a319e47f 100644 --- a/go.sum +++ b/go.sum @@ -65,8 +65,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= -github.com/bytedance/mockey v1.2.10 h1:4JlMpkm7HMXmTUtItid+iCu2tm61wvq+ca1X2u7ymzE= -github.com/bytedance/mockey v1.2.10/go.mod h1:bNrUnI1u7+pAc0TYDgPATM+wF2yzHxmNH+iDXg4AOCU= +github.com/bytedance/mockey v1.2.13 h1:jokWZAm/pUEbD939Rhznz615MKUCZNuvCFQlJ2+ntoo= +github.com/bytedance/mockey v1.2.13/go.mod h1:1BPHF9sol5R1ud/+0VEHGQq/+i2lN+GTsr3O2Q9IENY= github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -258,8 +258,8 @@ github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= +github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw= @@ -406,10 +406,10 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smarty/assertions v1.16.0 h1:EvHNkdRA4QHMrn75NZSoUQ/mAUXAYWfatfB01yTCzfY= +github.com/smarty/assertions v1.16.0/go.mod h1:duaaFdCS0K9dnoM50iyek/eYINOZ64gbh1Xlf6LG7AI= +github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= +github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60= github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js= github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -505,8 +505,8 @@ go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9i go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= -golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.12.0 h1:UsYJhbzPYGsT0HbEdmYcqtCv8UNGvnaL561NnIUvaKg= +golang.org/x/arch v0.12.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -654,8 +654,8 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= @@ -681,7 +681,6 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3 golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= diff --git a/pkg/util/certgenerator/generator_test.go b/pkg/util/certgenerator/generator_test.go index 93b2adfd..8749d4d7 100644 --- a/pkg/util/certgenerator/generator_test.go +++ b/pkg/util/certgenerator/generator_test.go @@ -84,10 +84,12 @@ func TestNewGenerator(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + mockey.UnPatchAll() + defer mockey.UnPatchAll() + // Mock kubernetes.NewForConfig if needed if tc.cfg != nil { mockey.Mock(kubernetes.NewForConfig).Return(&kubernetes.Clientset{}, nil).Build() - defer mockey.UnPatchAll() } generator, err := NewGenerator(tc.cfg, tc.namespace, tc.certName, tc.kubeConfigName) @@ -148,9 +150,11 @@ func TestGenerator_Generate(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + mockey.UnPatchAll() + defer mockey.UnPatchAll() + // Setup mocks tc.mockSetup() - defer mockey.UnPatchAll() err := generator.Generate(context.Background()) if tc.expectError { @@ -203,9 +207,11 @@ func TestGenerator_applyConfig(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + mockey.UnPatchAll() + defer mockey.UnPatchAll() + // Setup mocks tc.mockSetup() - defer mockey.UnPatchAll() err := generator.applyConfig(context.Background(), &x509.Certificate{}, nil, "test-kubeconfig") if tc.expectError { @@ -257,9 +263,11 @@ func TestGenerator_applyCertToSecret(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + mockey.UnPatchAll() + defer mockey.UnPatchAll() + // Setup mocks tc.mockSetup() - defer mockey.UnPatchAll() err := generator.applyCertToSecret(context.Background(), &x509.Certificate{}, nil) if tc.expectError { @@ -307,9 +315,11 @@ func TestGenerator_applyKubeConfigToConfigMap(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + mockey.UnPatchAll() + defer mockey.UnPatchAll() + // Setup mocks tc.mockSetup() - defer mockey.UnPatchAll() err := generator.applyKubeConfigToConfigMap(context.Background(), "test-kubeconfig") if tc.expectError { @@ -378,9 +388,11 @@ func TestGenerateConfig(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + mockey.UnPatchAll() + defer mockey.UnPatchAll() + // Setup mocks tc.mockSetup() - defer mockey.UnPatchAll() caCert, caKey, kubeConfig, err := generateConfig(tc.namespace) if tc.expectError { @@ -424,9 +436,11 @@ func TestGenerateCA(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + mockey.UnPatchAll() + defer mockey.UnPatchAll() + // Setup mocks tc.mockSetup() - defer mockey.UnPatchAll() cert, key, err := generateCA() if tc.expectError { @@ -468,9 +482,11 @@ func TestGenerateCert(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + mockey.UnPatchAll() + defer mockey.UnPatchAll() + // Setup mocks tc.mockSetup() - defer mockey.UnPatchAll() cert, key, err := generateCert(&x509.Certificate{}, &rsa.PrivateKey{}) if tc.expectError { @@ -514,9 +530,11 @@ func TestGenerateAdminKubeconfig(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + mockey.UnPatchAll() + defer mockey.UnPatchAll() + // Setup mocks tc.mockSetup() - defer mockey.UnPatchAll() kubeconfig, err := generateAdminKubeconfig(tc.namespace, tc.caCert, tc.caKey) if tc.expectError { From 64149e0514fb898b77b9d7f729a962300bf53177 Mon Sep 17 00:00:00 2001 From: elliotxx <951376975@qq.com> Date: Fri, 3 Jan 2025 23:50:00 +0800 Subject: [PATCH 3/3] chore: update dependencies in go.mod - Add 'github.com/swaggo/http-swagger/v2' and 'golang.org/x/sync' as direct dependencies - Remove 'github.com/swaggo/http-swagger/v2' from indirect dependencies - Correct a typo in the 'golang.org/x/tools' comment These changes ensure the project uses the latest versions of necessary libraries and corrects a minor documentation error. --- go.mod | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7d903b7f..2238ecf7 100644 --- a/go.mod +++ b/go.mod @@ -24,9 +24,11 @@ require ( github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 + github.com/swaggo/http-swagger/v2 v2.0.2 github.com/swaggo/swag v1.16.2 github.com/xwb1989/sqlparser v0.0.0-20171128062118-da747e0c62c4 go.uber.org/multierr v1.6.0 + golang.org/x/sync v0.5.0 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 k8s.io/api v0.26.1 @@ -134,7 +136,6 @@ require ( github.com/stoewer/go-strcase v1.2.0 // indirect github.com/stretchr/objx v0.5.0 // indirect github.com/swaggo/files/v2 v2.0.0 // indirect - github.com/swaggo/http-swagger/v2 v2.0.2 go.etcd.io/etcd/api/v3 v3.5.5 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect go.etcd.io/etcd/client/v3 v3.5.5 // indirect @@ -155,12 +156,11 @@ require ( golang.org/x/mod v0.14.0 // indirect golang.org/x/net v0.19.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect - golang.org/x/sync v0.5.0 golang.org/x/sys v0.28.0 // indirect golang.org/x/term v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/tools v0.16.0 // indirect; indirectt + golang.org/x/tools v0.16.0 // indirect gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect