mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-22 15:27:02 +00:00
Add tracing annotations
This patch changes several internal packages to receive and pass tracing annotations, making use of the new tracing library, so we can have better debugging information.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"blitiri.com.ar/go/chasquid/internal/testlib"
|
||||
"blitiri.com.ar/go/chasquid/internal/trace"
|
||||
)
|
||||
|
||||
func TestBasic(t *testing.T) {
|
||||
@@ -13,14 +14,16 @@ func TestBasic(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tr := trace.New("test", "basic")
|
||||
defer tr.Finish()
|
||||
|
||||
if !db.IncomingSecLevel("d1", SecLevel_PLAIN) {
|
||||
if !db.IncomingSecLevel(tr, "d1", SecLevel_PLAIN) {
|
||||
t.Errorf("new domain as plain not allowed")
|
||||
}
|
||||
if !db.IncomingSecLevel("d1", SecLevel_TLS_SECURE) {
|
||||
if !db.IncomingSecLevel(tr, "d1", SecLevel_TLS_SECURE) {
|
||||
t.Errorf("increment to tls-secure not allowed")
|
||||
}
|
||||
if db.IncomingSecLevel("d1", SecLevel_TLS_INSECURE) {
|
||||
if db.IncomingSecLevel(tr, "d1", SecLevel_TLS_INSECURE) {
|
||||
t.Errorf("decrement to tls-insecure was allowed")
|
||||
}
|
||||
|
||||
@@ -29,7 +32,7 @@ func TestBasic(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if db2.IncomingSecLevel("d1", SecLevel_TLS_INSECURE) {
|
||||
if db2.IncomingSecLevel(tr, "d1", SecLevel_TLS_INSECURE) {
|
||||
t.Errorf("decrement to tls-insecure was allowed in new DB")
|
||||
}
|
||||
}
|
||||
@@ -41,6 +44,8 @@ func TestNewDomain(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tr := trace.New("test", "basic")
|
||||
defer tr.Finish()
|
||||
|
||||
cases := []struct {
|
||||
domain string
|
||||
@@ -51,10 +56,10 @@ func TestNewDomain(t *testing.T) {
|
||||
{"secure", SecLevel_TLS_SECURE},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if !db.IncomingSecLevel(c.domain, c.level) {
|
||||
if !db.IncomingSecLevel(tr, c.domain, c.level) {
|
||||
t.Errorf("domain %q not allowed (in) at %s", c.domain, c.level)
|
||||
}
|
||||
if !db.OutgoingSecLevel(c.domain, c.level) {
|
||||
if !db.OutgoingSecLevel(tr, c.domain, c.level) {
|
||||
t.Errorf("domain %q not allowed (out) at %s", c.domain, c.level)
|
||||
}
|
||||
}
|
||||
@@ -67,6 +72,8 @@ func TestProgressions(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tr := trace.New("test", "basic")
|
||||
defer tr.Finish()
|
||||
|
||||
cases := []struct {
|
||||
domain string
|
||||
@@ -85,11 +92,11 @@ func TestProgressions(t *testing.T) {
|
||||
{"ssip", SecLevel_PLAIN, false},
|
||||
}
|
||||
for i, c := range cases {
|
||||
if ok := db.IncomingSecLevel(c.domain, c.lvl); ok != c.ok {
|
||||
if ok := db.IncomingSecLevel(tr, c.domain, c.lvl); ok != c.ok {
|
||||
t.Errorf("%2d %q in attempt for %s failed: got %v, expected %v",
|
||||
i, c.domain, c.lvl, ok, c.ok)
|
||||
}
|
||||
if ok := db.OutgoingSecLevel(c.domain, c.lvl); ok != c.ok {
|
||||
if ok := db.OutgoingSecLevel(tr, c.domain, c.lvl); ok != c.ok {
|
||||
t.Errorf("%2d %q out attempt for %s failed: got %v, expected %v",
|
||||
i, c.domain, c.lvl, ok, c.ok)
|
||||
}
|
||||
@@ -111,7 +118,10 @@ func TestErrors(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !db.IncomingSecLevel("d1", SecLevel_TLS_SECURE) {
|
||||
tr := trace.New("test", "basic")
|
||||
defer tr.Finish()
|
||||
|
||||
if !db.IncomingSecLevel(tr, "d1", SecLevel_TLS_SECURE) {
|
||||
t.Errorf("increment to tls-secure not allowed")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user