github.com/kubeshop/testkube@v1.17.23/pkg/logs/healthcheck_test.go (about)

     1  package logs
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/http"
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  
    12  	"github.com/kubeshop/testkube/pkg/log"
    13  )
    14  
    15  func TestLogsService_RunHealthcheckHandler(t *testing.T) {
    16  	t.Parallel()
    17  
    18  	ctx := context.Background()
    19  
    20  	svc := LogsService{log: log.DefaultLogger}
    21  	svc.WithRandomPort()
    22  	go svc.RunHealthCheckHandler(ctx)
    23  	go svc.RunGRPCServer(ctx, nil)
    24  	defer svc.Shutdown(ctx)
    25  
    26  	time.Sleep(100 * time.Millisecond)
    27  
    28  	resp, err := http.Get(fmt.Sprintf("http://%s/health", svc.httpAddress))
    29  	assert.NoError(t, err)
    30  	assert.Equal(t, 200, resp.StatusCode)
    31  }