From 5440b701aff0f13293ce7282fa06dbb205b4eaef Mon Sep 17 00:00:00 2001 From: D-Andreev Date: Wed, 27 May 2026 13:20:24 +0300 Subject: [PATCH 1/2] fix split node logic --- internal/radix/radix.go | 6 +++--- lambdamux_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/internal/radix/radix.go b/internal/radix/radix.go index d4ebb68..e06acf1 100644 --- a/internal/radix/radix.go +++ b/internal/radix/radix.go @@ -107,13 +107,13 @@ func (n *Node) Insert(input string) *Node { node.paramNames = getParamNames(node.value) child.addEdge(node) search = search[commonPrefix:] - newNode := NewNode(search, true) if len(search) == 0 { child.isComplete = true - } else { - child.addEdge(newNode) + return child } + newNode := NewNode(search, true) + child.addEdge(newNode) return newNode } } diff --git a/lambdamux_test.go b/lambdamux_test.go index faff82b..14ca1a3 100644 --- a/lambdamux_test.go +++ b/lambdamux_test.go @@ -293,3 +293,43 @@ func createHandler(method, path string) HandlerFunc { }, nil } } + +func TestGETCompaniesRootRegisteredAfterNestedRoutes(t *testing.T) { + router := NewLambdaMux() + + router.GET("/companies/salary-ranges", createHandler("GET", "/companies/salary-ranges")) + router.GET("/companies/median-salary", createHandler("GET", "/companies/median-salary")) + router.GET("/companies", createHandler("GET", "/companies")) + + for _, tc := range []struct { + path string + expectedMessage string + }{ + { + path: "/companies/salary-ranges", + expectedMessage: "Handled GET request for /companies/salary-ranges", + }, + { + path: "/companies/median-salary", + expectedMessage: "Handled GET request for /companies/median-salary", + }, + { + path: "/companies", + expectedMessage: "Handled GET request for /companies", + }, + } { + t.Run(tc.path, func(t *testing.T) { + req := events.APIGatewayProxyRequest{ + HTTPMethod: "GET", + Path: tc.path, + } + resp, err := router.Handle(context.Background(), req) + assert.NoError(t, err) + assert.Equal(t, 200, resp.StatusCode, "expected registered route to match") + + var body map[string]interface{} + assert.NoError(t, json.Unmarshal([]byte(resp.Body), &body)) + assert.Equal(t, tc.expectedMessage, body["message"]) + }) + } +} From a6405e89b2b8305c0b808f83c79e1ea963ee4936 Mon Sep 17 00:00:00 2001 From: D-Andreev Date: Wed, 27 May 2026 13:23:31 +0300 Subject: [PATCH 2/2] fix actions --- .github/workflows/test.yml | 78 +++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c66509d..03828ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,50 +2,48 @@ name: Tets on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: - build: name: Build and Test runs-on: ubuntu-latest steps: - - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ^1.19 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -v ./... - - - name: Build Example - run: | - cd examples - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bootstrap example.go - - - name: Benchmark - run: go test -bench=. -benchmem ./... | tee bench.txt - - - name: Upload benchmark results - uses: actions/upload-artifact@v3 - with: - name: benchmark-results - path: bench.txt + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.19 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Get dependencies + run: | + go get -v -t -d ./... + if [ -f Gopkg.toml ]; then + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh + dep ensure + fi + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... + + - name: Build Example + run: | + cd examples + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bootstrap example.go + + - name: Benchmark + run: go test -bench=. -benchmem ./... | tee bench.txt + + - name: Upload benchmark results + uses: actions/upload-artifact@v4 + with: + name: benchmark-results + path: bench.txt