Skip to content

Commit

Permalink
test: add health system test
Browse files Browse the repository at this point in the history
  • Loading branch information
andydunstall committed May 4, 2024
1 parent 105473e commit 13382df
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@ jobs:
- name: Build
run: go build ./...

test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Unit Tests
run: go test ./...
run: go test ./... -v

- name: Integration Tests
run: go test ./... -tags integration
run: go test ./... -tags integration -v

- name: System Tests
run: go test ./tests -tags system -v

lint:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ unit-test:
integration-test:
go test ./... -tags integration -v

.PHONY: system-test
system-test:
go test ./tests -tags system -v

.PHONY: fmt
fmt:
go fmt ./...
Expand Down
53 changes: 53 additions & 0 deletions tests/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//go:build system

package tests

import (
"context"
"net/http"
"testing"

"github.com/andydunstall/pico/pkg/log"
"github.com/andydunstall/pico/server"
"github.com/andydunstall/pico/server/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestServer(t *testing.T) {
serverConf := defaultServerConfig()
server, err := server.NewServer(serverConf, log.NewNopLogger())
require.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
require.NoError(t, server.Run(ctx))
}()

t.Run("health status", func(t *testing.T) {
resp, err := http.Get(
"http://" + serverConf.Admin.AdvertiseAddr + "/health",
)
assert.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
})
}

// defaultServerConfig returns the default server configuration for local
// tests.
func defaultServerConfig() *config.Config {
return &config.Config{
Proxy: config.ProxyConfig{
BindAddr: "127.0.0.1:0",
GatewayTimeout: 1,
},
Upstream: config.UpstreamConfig{
BindAddr: "127.0.0.1:0",
},
Admin: config.AdminConfig{
BindAddr: "127.0.0.1:0",
},
}
}

0 comments on commit 13382df

Please sign in to comment.