Files

34 lines
660 B
Go

package audit
import (
"sync"
"testing"
)
func TestCounterNoDataRace(t *testing.T) {
var c Counter
var wg sync.WaitGroup
for i := 0; i < 50; i++ {
wg.Add(1)
go func() {
defer wg.Done()
c.Inc()
}()
}
wg.Wait()
if c.Value() != 50 {
t.Fatalf("got %d, want 50", c.Value())
}
}
func TestExtractBearerToken(t *testing.T) {
if tok, ok := ExtractBearerToken("Bearer secret123"); !ok || tok != "secret123" {
t.Fatalf("got (%q, %v), want (secret123, true)", tok, ok)
}
for _, bad := range []string{"Bearer ", "Basic abc", "Malformed", ""} {
if _, ok := ExtractBearerToken(bad); ok {
t.Errorf("expected ok=false for %q", bad)
}
}
}