Skip to content

Commit 75a01da

Browse files
committed
Refactor server readiness waiting mechanism for the integration tests
1 parent e633134 commit 75a01da

File tree

5 files changed

+12
-36
lines changed

5 files changed

+12
-36
lines changed

.github/workflows/test-integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ jobs:
1414
badge-title: Coverage (integration)
1515
coverage-file: assets/coverage/integration/coverage.out
1616
report: true
17-
report-path: assets/coverage/integration
17+
output-path: assets/coverage/integration
1818
chart: true

.github/workflows/test-unit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ jobs:
1414
badge-title: Coverage (unit)
1515
coverage-file: assets/coverage/unit/coverage.out
1616
report: true
17-
report-path: assets/coverage/unit
17+
output-path: assets/coverage/unit
1818
chart: true

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
----
1010

1111
[![Lint Golangci](https://github.com/mgerasimchuk/protty/actions/workflows/lint-golangci.yml/badge.svg)](https://github.com/mgerasimchuk/protty/actions/workflows/lint-golangci.yml)
12-
[![Test Unit](https://github.com/mgerasimchuk/protty/actions/workflows/test-unit.yml/badge.svg)](https://github.com/mgerasimchuk/protty/actions/workflows/test-unit.yml)
12+
[![Test (unit)](https://github.com/mgerasimchuk/protty/actions/workflows/test-unit.yml/badge.svg)](https://github.com/mgerasimchuk/protty/actions/workflows/test-unit.yml)
1313
[![Coverage (unit)](https://github.com/mgerasimchuk/protty/wiki/assets/coverage/unit/coverage.svg)](https://github.com/mgerasimchuk/protty/wiki/Test-coverage-report)
14-
[![Test Integration](https://github.com/mgerasimchuk/protty/actions/workflows/test-integration.yml/badge.svg)](https://github.com/mgerasimchuk/protty/actions/workflows/test-integration.yml)
14+
[![Test (integration)](https://github.com/mgerasimchuk/protty/actions/workflows/test-integration.yml/badge.svg)](https://github.com/mgerasimchuk/protty/actions/workflows/test-integration.yml)
1515
[![Coverage (integration)](https://github.com/mgerasimchuk/protty/wiki/assets/coverage/integration/coverage.svg)](https://github.com/mgerasimchuk/protty/wiki/Test-coverage-report)
1616

1717
Protty is an HTTP proxy written in Go that redirects, intercepts, and modifies both requests to a remote host and their

internal/infrastructure/app/mock/logrus_hook.go

-27
This file was deleted.

internal/infrastructure/app/protty_test.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import (
77
"context"
88
"fmt"
99
"github.com/gavv/httpexpect/v2"
10-
"github.com/sirupsen/logrus"
1110
"github.com/stretchr/testify/assert"
1211
"io"
1312
"net/http"
1413
"os"
15-
"protty/internal/infrastructure/app/mock"
1614
"protty/internal/infrastructure/config"
1715
"testing"
16+
"time"
1817
)
1918

2019
func TestStartCommand(t *testing.T) {
@@ -71,12 +70,16 @@ func TestStartCommand(t *testing.T) {
7170
cfg := config.GetStartCommandConfig()
7271
prottyApp := NewProttyApp(cfg)
7372
prottyApp.logger.SetOutput(io.Discard)
74-
logrusHook := mock.NewLogrusHook([]logrus.Level{logrus.InfoLevel}, 50)
75-
prottyApp.logger.Hooks.Add(logrusHook)
7673
go func() { assert.NoError(t, prottyApp.Start()) }()
7774

7875
// waiting for the first info message from logger as a signal that the proxy is ready to handle requests
79-
<-logrusHook.EntryChan()
76+
for i := 0; i < 5; i++ {
77+
_, err := http.Get("http://0.0.0.0:80")
78+
if err == nil {
79+
break
80+
}
81+
time.Sleep(50 * time.Millisecond)
82+
}
8083

8184
// test
8285
e := httpexpect.Default(t, fmt.Sprintf("http://0.0.0.0:%d", cfg.LocalPort.Value))

0 commit comments

Comments
 (0)