logtail: add a test to upload logs to local server

Start an HTTP server to accept POST requests, and upload some logs to
it. Check that uploaded logs were received.

Code in logtail:drainPending was not being reliably exercised by other
tests. This shows up in code coverage reports, as lines of code in
drainPending are alternately added and subtracted from code coverage.
This test will reliably exercise and verify this code.

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
Denton Gentry 2021-01-10 15:03:57 -08:00 committed by Denton Gentry
parent 0aed59b691
commit 2c328da094

View File

@ -6,6 +6,8 @@
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
)
@ -20,6 +22,27 @@ func TestFastShutdown(t *testing.T) {
l.Shutdown(ctx)
}
func TestUploadMessages(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
uploads := 0
testServ := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
uploads += 1
}))
l := NewLogger(Config{BaseURL: testServ.URL}, t.Logf)
for i := 1; i < 10; i++ {
l.Write([]byte("log line"))
}
l.Shutdown(ctx)
cancel()
if uploads == 0 {
t.Error("no log uploads")
}
}
var sink []byte
func TestLoggerEncodeTextAllocs(t *testing.T) {