diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 03ca69f..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Go CI - -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - test_and_lint: - name: Test, Lint, and Coverage - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: 1.20 - - - name: Install dependencies - run: go mod download - - - name: Run tests with coverage - run: go test ./... -v -coverprofile=coverage.out - - - name: Calculate coverage - run: go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}' - id: coverage - - - name: Check coverage threshold - run: | - COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}') - if (( $(echo "$COVERAGE < 75.0" | bc -l) )); then - echo "ERROR: Code coverage ($COVERAGE%) is below the threshold of 75%." - exit 1 - else - echo "Code coverage ($COVERAGE%) meets the threshold of 75%." - fi - - - name: Install GolangCI-Lint - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@1.56.1 - - - name: Run GolangCI-Lint - run: golangci-lint run diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..9ff1589 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,32 @@ +name: Lint +on: + push: + branches: + - master + pull_request: + branches: + - master +permissions: + contents: read +jobs: + lint: + strategy: + matrix: + go: [ '1.20' ] + fail-fast: true + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Setup Go ${{ matrix.go }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go }} + cache: false + + - name: Run GolangCI-Lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.56.1 + args: --timeout=5m \ No newline at end of file diff --git a/.github/workflows/sec.yml b/.github/workflows/sec.yml new file mode 100644 index 0000000..e12987e --- /dev/null +++ b/.github/workflows/sec.yml @@ -0,0 +1,32 @@ +name: Security Scan + +on: + push: + branches: + - master + pull_request: + branches: + - master + +permissions: + contents: read + id-token: write + issues: write + pull-requests: write + +jobs: + TruffleHog: + runs-on: ubuntu-latest + defaults: + run: + shell: bash + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Secret Scanning + uses: trufflesecurity/trufflehog@main + with: + extra_args: --only-verified diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1da641f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,47 @@ +name: Test + +on: + push: + branches: + - master + pull_request: + branches: + - master + +permissions: + contents: read + +jobs: + test_and_lint: + name: Test, Lint, and Coverage + strategy: + matrix: + go: [ '1.20' ] + os: [ ubuntu-latest, macos-latest, windows-latest ] + fail-fast: true + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Go ${{ matrix.go }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go }} + cache: false + + - name: Install dependencies + run: go mod download + + - name: Run tests with coverage + run: go test -race -cover -coverprofile="coverage.out" -covermode=atomic -v ./... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + files: ./coverage.out + + - name: Calculate coverage + run: go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}' + id: coverage diff --git a/httpclient/example_rate_limiting_round_tripper_test.go b/httpclient/example_rate_limiting_round_tripper_test.go index bab84b4..8a37756 100644 --- a/httpclient/example_rate_limiting_round_tripper_test.go +++ b/httpclient/example_rate_limiting_round_tripper_test.go @@ -52,7 +52,7 @@ func ExampleNewRateLimitingRoundTripper() { prev = now } delta := time.Since(start) - time.Second*2 - if delta > time.Millisecond*10 { + if delta > time.Millisecond*20 { fmt.Println("Total time is much greater than 2s") } else { fmt.Println("Total time is about 2s") diff --git a/httpserver/config.go b/httpserver/config.go index 5c197a2..a910a90 100644 --- a/httpserver/config.go +++ b/httpserver/config.go @@ -28,7 +28,7 @@ const ( cfgKeyServerLogRequestStart = "server.log.requestStart" cfgKeyServerLogRequestHeaders = "server.log.requestHeaders" cfgKeyServerLogExcludedEndpoints = "server.log.excludedEndpoints" - cfgKeyServerLogSecretQueryParams = "server.log.secretQueryParams" //nolint:gosec + cfgKeyServerLogSecretQueryParams = "server.log.secretQueryParams" // nolint:gosec // false positive cfgKeyServerLogAddRequestInfo = "server.log.addRequestInfo" cfgKeyServerLogSlowRequestThreshold = "server.log.slowRequestThreshold" ) diff --git a/httpserver/health_check_test.go b/httpserver/health_check_test.go index dc64efa..7d59ec5 100644 --- a/httpserver/health_check_test.go +++ b/httpserver/health_check_test.go @@ -177,7 +177,7 @@ func TestHealthCheckHandlerContext_ServeHTTP(t *testing.T) { timeout := 1 * time.Millisecond h := NewHealthCheckHandlerContext(func(ctx context.Context) (HealthCheckResult, error) { - time.Sleep(timeout + 1*time.Millisecond) + time.Sleep(timeout + 5*time.Millisecond) return HealthCheckResult{}, ctx.Err() }) resp := httptest.NewRecorder() diff --git a/httpserver/middleware/rate_limit_test.go b/httpserver/middleware/rate_limit_test.go index 087183a..4d679ce 100644 --- a/httpserver/middleware/rate_limit_test.go +++ b/httpserver/middleware/rate_limit_test.go @@ -73,11 +73,11 @@ func TestRateLimitHandler_ServeHTTP(t *testing.T) { }) t.Run("leaky bucket, maxRate=10r/s, maxBurst=10, no key", func(t *testing.T) { - rate := Rate{10, time.Second} + rate := Rate{5, time.Second} const ( - maxBurst = 10 - concurrentReqsNum = 20 - serialReqsNum = 10 + maxBurst = 5 + concurrentReqsNum = 10 + serialReqsNum = 5 ) emissionInterval := rate.Duration / time.Duration(rate.Count) @@ -192,12 +192,12 @@ func TestRateLimitHandler_ServeHTTP(t *testing.T) { t.Run("leaky bucket, maxRate=10r/s, maxBurst=10, by key", func(t *testing.T) { const headerClientID = "X-Client-ID" - rate := Rate{10, time.Second} + rate := Rate{5, time.Second} const ( - maxBurst = 10 - concurrentReqsNum = 20 - serialReqsNum = 10 - clientsNum = 5 + maxBurst = 5 + concurrentReqsNum = 10 + serialReqsNum = 5 + clientsNum = 3 ) emissionInterval := rate.Duration / time.Duration(rate.Count)