diff --git a/.github/workflows/lint-test-code.yaml b/.github/workflows/lint-test-code.yaml new file mode 100644 index 00000000..ecf87961 --- /dev/null +++ b/.github/workflows/lint-test-code.yaml @@ -0,0 +1,45 @@ +name: Lint & Test Code + +on: + push: + branches: + - "**" + - "!main" + - "!master" + +env: + go_version: 1.22 + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint-test-code: + name: Lint & Test Code + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: "${{ env.go_version }}" + + - name: Setup Just + uses: extractions/setup-just@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Run Code Linting Test + run: just lint >> "$GITHUB_STEP_SUMMARY" + + - name: Run Tests + run: | + just test + + - name: Upload Code Coverage Report + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/pkg/config-api-client/.gitignore b/.gitignore similarity index 96% rename from pkg/config-api-client/.gitignore rename to .gitignore index daf913b1..e2240335 100644 --- a/pkg/config-api-client/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ _testmain.go *.exe *.test *.prof + +.coverage diff --git a/Justfile b/Justfile index 15b37752..b020ebbf 100644 --- a/Justfile +++ b/Justfile @@ -18,6 +18,30 @@ generate-config-api-client: retrieve-config-api-openapi-spec --git-user-id aruba-uxi \ --git-repo-id configuration-api-terraform-provider/{{ CONFIG_API_DIR }} \ cd {{ CONFIG_API_DIR }} && go mod tidy + just fmt-client test-client: - cd {{ CONFIG_API_DIR }} && go test -v ./... + cd {{ CONFIG_API_DIR }} && go test -v ./... -race -covermode=atomic -coverprofile=.coverage + +fmt-client: + gofmt -w pkg/config-api-client + +lint-client: + #!/usr/bin/env bash + + if [ -n "$(gofmt -d pkg/config-api-client)" ]; then + echo "Error: (gofmt) formatting required" >&2 + exit 1 + fi + +test: + just test-client + +lint: + just lint-client + +fmt: + just fmt-client + +clean: + find . -name ".coverage" -type f -delete diff --git a/pkg/config-api-client/.openapi-generator-ignore b/pkg/config-api-client/.openapi-generator-ignore index 080aeef2..e57e6ea6 100644 --- a/pkg/config-api-client/.openapi-generator-ignore +++ b/pkg/config-api-client/.openapi-generator-ignore @@ -22,5 +22,6 @@ # Then explicitly reverse the ignore rule for a single file: #!docs/README.md -git_push.sh +.gitignore .travis.yml +git_push.sh diff --git a/pkg/config-api-client/api_health.go b/pkg/config-api-client/api_health.go index 57b07621..c2f30a3f 100644 --- a/pkg/config-api-client/api_health.go +++ b/pkg/config-api-client/api_health.go @@ -18,12 +18,11 @@ import ( "net/url" ) - // HealthAPIService HealthAPI service type HealthAPIService service type ApiGetLivezHealthLivezGetRequest struct { - ctx context.Context + ctx context.Context ApiService *HealthAPIService } @@ -36,24 +35,25 @@ GetLivezHealthLivezGet Live health check Check the health of the service. - @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). - @return ApiGetLivezHealthLivezGetRequest + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetLivezHealthLivezGetRequest */ func (a *HealthAPIService) GetLivezHealthLivezGet(ctx context.Context) ApiGetLivezHealthLivezGetRequest { return ApiGetLivezHealthLivezGetRequest{ ApiService: a, - ctx: ctx, + ctx: ctx, } } // Execute executes the request -// @return LivenessResponse +// +// @return LivenessResponse func (a *HealthAPIService) GetLivezHealthLivezGetExecute(r ApiGetLivezHealthLivezGetRequest) (*LivenessResponse, *http.Response, error) { var ( - localVarHTTPMethod = http.MethodGet - localVarPostBody interface{} - formFiles []formFile - localVarReturnValue *LivenessResponse + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LivenessResponse ) localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "HealthAPIService.GetLivezHealthLivezGet") @@ -122,7 +122,7 @@ func (a *HealthAPIService) GetLivezHealthLivezGetExecute(r ApiGetLivezHealthLive } type ApiGetReadyzHealthReadyzGetRequest struct { - ctx context.Context + ctx context.Context ApiService *HealthAPIService } @@ -135,24 +135,25 @@ GetReadyzHealthReadyzGet Ready health check Check if the service is ready to process requests. - @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). - @return ApiGetReadyzHealthReadyzGetRequest + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetReadyzHealthReadyzGetRequest */ func (a *HealthAPIService) GetReadyzHealthReadyzGet(ctx context.Context) ApiGetReadyzHealthReadyzGetRequest { return ApiGetReadyzHealthReadyzGetRequest{ ApiService: a, - ctx: ctx, + ctx: ctx, } } // Execute executes the request -// @return ReadinessResponse +// +// @return ReadinessResponse func (a *HealthAPIService) GetReadyzHealthReadyzGetExecute(r ApiGetReadyzHealthReadyzGetRequest) (*ReadinessResponse, *http.Response, error) { var ( - localVarHTTPMethod = http.MethodGet - localVarPostBody interface{} - formFiles []formFile - localVarReturnValue *ReadinessResponse + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ReadinessResponse ) localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "HealthAPIService.GetReadyzHealthReadyzGet") @@ -212,8 +213,8 @@ func (a *HealthAPIService) GetReadyzHealthReadyzGetExecute(r ApiGetReadyzHealthR newErr.error = err.Error() return localVarReturnValue, localVarHTTPResponse, newErr } - newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) - newErr.model = v + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v } return localVarReturnValue, localVarHTTPResponse, newErr } @@ -231,7 +232,7 @@ func (a *HealthAPIService) GetReadyzHealthReadyzGetExecute(r ApiGetReadyzHealthR } type ApiGetStatusHealthStatusGetRequest struct { - ctx context.Context + ctx context.Context ApiService *HealthAPIService } @@ -244,24 +245,25 @@ GetStatusHealthStatusGet Service stats endpoint Check basic service details. - @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). - @return ApiGetStatusHealthStatusGetRequest + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiGetStatusHealthStatusGetRequest */ func (a *HealthAPIService) GetStatusHealthStatusGet(ctx context.Context) ApiGetStatusHealthStatusGetRequest { return ApiGetStatusHealthStatusGetRequest{ ApiService: a, - ctx: ctx, + ctx: ctx, } } // Execute executes the request -// @return StatusResponse +// +// @return StatusResponse func (a *HealthAPIService) GetStatusHealthStatusGetExecute(r ApiGetStatusHealthStatusGetRequest) (*StatusResponse, *http.Response, error) { var ( - localVarHTTPMethod = http.MethodGet - localVarPostBody interface{} - formFiles []formFile - localVarReturnValue *StatusResponse + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *StatusResponse ) localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "HealthAPIService.GetStatusHealthStatusGet") diff --git a/pkg/config-api-client/client.go b/pkg/config-api-client/client.go index 58cf7944..d9d8962d 100644 --- a/pkg/config-api-client/client.go +++ b/pkg/config-api-client/client.go @@ -31,14 +31,13 @@ import ( "strings" "time" "unicode/utf8" - ) var ( JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) - queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) + queryDescape = strings.NewReplacer("%5B", "[", "%5D", "]") ) // APIClient manages communication with the FastAPI API v1.0.0 @@ -125,15 +124,15 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { return nil } -func parameterValueToString( obj interface{}, key string ) string { +func parameterValueToString(obj interface{}, key string) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { return fmt.Sprintf("%v", obj) } - var param,ok = obj.(MappedNullable) + var param, ok = obj.(MappedNullable) if !ok { return "" } - dataMap,err := param.ToMap() + dataMap, err := param.ToMap() if err != nil { return "" } @@ -149,81 +148,81 @@ func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix stri value = "null" } else { switch v.Kind() { - case reflect.Invalid: - value = "invalid" + case reflect.Invalid: + value = "invalid" - case reflect.Struct: - if t,ok := obj.(MappedNullable); ok { - dataMap,err := t.ToMap() - if err != nil { - return - } - parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) - return - } - if t, ok := obj.(time.Time); ok { - parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339Nano), collectionType) - return - } - value = v.Type().String() + " value" - case reflect.Slice: - var indValue = reflect.ValueOf(obj) - if indValue == reflect.ValueOf(nil) { + case reflect.Struct: + if t, ok := obj.(MappedNullable); ok { + dataMap, err := t.ToMap() + if err != nil { return } - var lenIndValue = indValue.Len() - for i:=0;i