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
78 changes: 38 additions & 40 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions internal/radix/radix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
40 changes: 40 additions & 0 deletions lambdamux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
})
}
}
Loading