Skip to content

Commit

Permalink
ci: test Caddy module
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Jan 5, 2021
1 parent 03289c9 commit 86b5848
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
Expand All @@ -23,19 +24,35 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.15'

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod # Module download cache
~/.cache/go-build # Build cache (Linux)
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install project dependencies
run: go get
- name: Build
run: CGO_ENABLED=0 GOOS=linux go build -v -a -ldflags '-extldflags "-static"' .

- name: Use go-deadlock
run: ./tests/use-go-deadlock.sh

- name: Test
run: go test -race -covermode atomic -coverprofile=profile.cov ./...

- name: Test Caddy module
run: go test -timeout 1m -race ./...
working-directory: ./caddy

- name: Upload coverage results
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
54 changes: 32 additions & 22 deletions caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@ const (
func TestMercure(t *testing.T) {
tester := caddytest.NewTester(t)
tester.InitServer(`
localhost:9080
{
http_port 9080
https_port 9443
}
localhost:9080 {
route {
mercure {
anonymous
publisher_jwt !ChangeMe!
cache_size_approx 0
}
route {
mercure {
anonymous
publisher_jwt !ChangeMe!
cache_size_approx 0
respond 404
}
respond 404
}`, "caddyfile")
}
`, "caddyfile")

var connected sync.WaitGroup
var received sync.WaitGroup
Expand All @@ -43,7 +48,7 @@ func TestMercure(t *testing.T) {

go func() {
cx, cancel := context.WithCancel(context.Background())
req, _ := http.NewRequest("GET", "https://localhost:9080/.well-known/mercure?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1", nil)
req, _ := http.NewRequest("GET", "http://localhost:9080/.well-known/mercure?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1", nil)
req = req.WithContext(cx)
resp, err := http.DefaultClient.Do(req)
require.Nil(t, err)
Expand Down Expand Up @@ -74,7 +79,7 @@ func TestMercure(t *testing.T) {
connected.Wait()

body := url.Values{"topic": {"http://example.com/foo/1"}, "data": {"bar"}, "id": {"bar"}}
req, err := http.NewRequest("POST", "https://localhost:9080/.well-known/mercure", strings.NewReader(body.Encode()))
req, err := http.NewRequest("POST", "http://localhost:9080/.well-known/mercure", strings.NewReader(body.Encode()))
require.Nil(t, err)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "Bearer "+publisherJWT)
Expand All @@ -96,17 +101,22 @@ func TestJWTPlaceholders(t *testing.T) {

tester := caddytest.NewTester(t)
tester.InitServer(`
localhost:9080
{
http_port 9080
https_port 9443
}
localhost:9080 {
route {
mercure {
anonymous
publisher_jwt {env.TEST_JWT_KEY} {env.TEST_JWT_ALG}
cache_size_approx 0
}
route {
mercure {
anonymous
publisher_jwt {env.TEST_JWT_KEY} {env.TEST_JWT_ALG}
cache_size_approx 0
respond 404
}
respond 404
}`, "caddyfile")
}
`, "caddyfile")

var connected sync.WaitGroup
var received sync.WaitGroup
Expand All @@ -115,7 +125,7 @@ func TestJWTPlaceholders(t *testing.T) {

go func() {
cx, cancel := context.WithCancel(context.Background())
req, _ := http.NewRequest("GET", "https://localhost:9080/.well-known/mercure?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1", nil)
req, _ := http.NewRequest("GET", "http://localhost:9080/.well-known/mercure?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1", nil)
req = req.WithContext(cx)
resp, err := http.DefaultClient.Do(req)
require.Nil(t, err)
Expand Down Expand Up @@ -146,7 +156,7 @@ func TestJWTPlaceholders(t *testing.T) {
connected.Wait()

body := url.Values{"topic": {"http://example.com/foo/1"}, "data": {"bar"}, "id": {"bar"}}
req, err := http.NewRequest("POST", "https://localhost:9080/.well-known/mercure", strings.NewReader(body.Encode()))
req, err := http.NewRequest("POST", "http://localhost:9080/.well-known/mercure", strings.NewReader(body.Encode()))
require.Nil(t, err)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "Bearer "+publisherJWTRSA)
Expand Down

0 comments on commit 86b5848

Please sign in to comment.