Skip to content

Commit

Permalink
Refactor server readiness waiting mechanism for the integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerasimchuk committed Oct 30, 2023
1 parent e633134 commit 75a01da
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
badge-title: Coverage (integration)
coverage-file: assets/coverage/integration/coverage.out
report: true
report-path: assets/coverage/integration
output-path: assets/coverage/integration
chart: true
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
badge-title: Coverage (unit)
coverage-file: assets/coverage/unit/coverage.out
report: true
report-path: assets/coverage/unit
output-path: assets/coverage/unit
chart: true
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
----

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

Protty is an HTTP proxy written in Go that redirects, intercepts, and modifies both requests to a remote host and their
Expand Down
27 changes: 0 additions & 27 deletions internal/infrastructure/app/mock/logrus_hook.go

This file was deleted.

13 changes: 8 additions & 5 deletions internal/infrastructure/app/protty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"context"
"fmt"
"github.com/gavv/httpexpect/v2"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"io"
"net/http"
"os"
"protty/internal/infrastructure/app/mock"
"protty/internal/infrastructure/config"
"testing"
"time"
)

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

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

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

0 comments on commit 75a01da

Please sign in to comment.