Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
docker-ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go 1.22.5
- uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22.5'
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: latest
8 changes: 5 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Push in Main
on:
push:
branches: main
branches: ["main"]
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
lint:
uses: ./.github/workflows/golangci-lint.yml
test:
uses: ./.github/workflows/test.yml
build:
uses: ./.github/workflows/build.yml
needs: lint
needs: [lint, test]
10 changes: 10 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Pull Request Checks
on:
pull_request:
branches: ["main"]

jobs:
lint:
uses: ./.github/workflows/golangci-lint.yml
test:
uses: ./.github/workflows/test.yml
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Go Tests
on: workflow_call

permissions:
contents: read

jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

# - name: Download dependencies
# run: go mod download

- name: Run tests
uses: robherley/go-test-action@v0
73 changes: 44 additions & 29 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
version: "2"
linters:
enable:
# enabled by default
- errcheck # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases.
- gosimple # Linter for Go source code that specializes in simplifying code.
- govet # Vet examines Go source code and reports suspicious constructs. It is roughly the same as 'go vet' and uses its passes.
- ineffassign # Detects when assignments to existing variables are not used.
- staticcheck # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
- unused # Checks Go code for unused constants, variables, functions and types.
# additional
- goimports # Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode.
- misspell # Finds commonly misspelled English words.
- sloglint # Ensure consistent code style when using log/slog.
- godox # Tool for detection of FIXME, TODO and other comment keywords.
- funlen # Tool for detection of long functions.
- gocognit # Computes and checks the cognitive complexity of functions.
linters-settings:
sloglint:
no-mixed-args: true
kv-only: true
attr-only: false
no-global: ""
context: "scope"
static-msg: true
no-raw-keys: false
key-naming-case: camel
forbidden-keys:
- time
- level
- msg
- source
args-on-sep-lines: false
godox:
keywords:
- TODO
- BUG
- FIXME
funlen:
lines: 60
statements: 40
ignore-comments: false
gocognit:
min-complexity: 20
settings:
funlen:
lines: 60
statements: 40
ignore-comments: false
gocognit:
min-complexity: 20
godox:
keywords:
- TODO
- BUG
- FIXME
sloglint:
no-mixed-args: true
kv-only: true
attr-only: false
no-global: ""
context: scope
static-msg: true
no-raw-keys: false
key-naming-case: camel
forbidden-keys:
- time
- level
- msg
- source
args-on-sep-lines: false
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
formatters:
enable:
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.5-alpine AS build-stage
FROM golang:1.25.2-alpine AS build-stage

WORKDIR /app

Expand Down
6 changes: 5 additions & 1 deletion database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func issueSyncAlgorithm(existingIssues []models.Issue, typesFromConfig []string)
return toDelete, toCreate
}

func TestIssueSyncAlgorithm(t *testing.T) {
func TestIssueSyncAlgorithm_BasicCases(t *testing.T) {
t.Run("creates new issue types when none exist", func(t *testing.T) {
existingIssues := []models.Issue{} // Empty database
typesFromConfig := []string{"bug", "feature"}
Expand Down Expand Up @@ -73,7 +73,9 @@ func TestIssueSyncAlgorithm(t *testing.T) {
assert.Equal(t, "old-feature", toDelete[0].Name, "Should delete old-feature")
assert.Equal(t, []string{"enhancement"}, toCreate, "Should create enhancement")
})
}

func TestIssueSyncAlgorithm_EdgeCases(t *testing.T) {
t.Run("handles empty config - removes all existing issues", func(t *testing.T) {
existingIssues := []models.Issue{
{Name: "bug"},
Expand Down Expand Up @@ -114,7 +116,9 @@ func TestIssueSyncAlgorithm(t *testing.T) {
assert.Contains(t, toCreate, "bug", "Should include bug in creation list")
assert.Contains(t, toCreate, "feature", "Should include feature in creation list")
})
}

func TestIssueSyncAlgorithm_ComplexScenario(t *testing.T) {
t.Run("handles complex synchronization scenario", func(t *testing.T) {
existingIssues := []models.Issue{
{Name: "bug"},
Expand Down
27 changes: 8 additions & 19 deletions gin_middlewares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,7 @@ import (
"gorm.io/gorm"
)

// Helper to create test context with logger
func createTestContextWithLogger() (*gin.Context, *httptest.ResponseRecorder) {
gin.SetMode(gin.TestMode)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)

// Create a basic request first
c.Request = httptest.NewRequest("GET", "/", nil)

// Set up a logger in the context
logger := slog.New(slog.NewTextHandler(bytes.NewBuffer(nil), nil))
ctx := context.WithValue(c.Request.Context(), contextLogger, logger)
c.Request = c.Request.WithContext(ctx)

return c, w
}

func TestSubmitTokenMiddleware(t *testing.T) {
func TestSubmitTokenMiddleware_AllowedCases(t *testing.T) {
t.Run("allows request when token is empty (no token required)", func(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
Expand All @@ -60,7 +43,9 @@ func TestSubmitTokenMiddleware(t *testing.T) {
assert.False(t, c.IsAborted())
assert.Equal(t, http.StatusOK, w.Code)
})
}

func TestSubmitTokenMiddleware_BlockedCases(t *testing.T) {
t.Run("blocks request when token is required but not provided", func(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
Expand Down Expand Up @@ -98,7 +83,7 @@ func TestSubmitTokenMiddleware(t *testing.T) {
})
}

func TestReportMiddleware(t *testing.T) {
func TestReportMiddleware_InvalidJSONSyntax(t *testing.T) {
t.Run("rejects request with invalid JSON syntax", func(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
Expand All @@ -124,7 +109,9 @@ func TestReportMiddleware(t *testing.T) {
// Just check that there's an error, the exact message may vary
assert.NotEmpty(t, response["error"])
})
}

func TestReportMiddleware_InvalidValidation(t *testing.T) {
t.Run("rejects request with invalid boolean value", func(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
Expand Down Expand Up @@ -160,7 +147,9 @@ func TestReportMiddleware(t *testing.T) {
assert.True(t, ok)
assert.True(t, len(errorStr) > 0, "Error message should not be empty")
})
}

func TestReportMiddleware_MissingFields(t *testing.T) {
t.Run("rejects request when satisfied field is missing", func(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
Expand Down
Loading