Skip to content

Commit

Permalink
test: New unit test for TraceDatabase function
Browse files Browse the repository at this point in the history
  • Loading branch information
laynax committed Feb 22, 2023
1 parent 3c1371e commit 69dfa41
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/instrumentation/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,18 @@ func TestInstrumentDatabase(t *testing.T) {
}
}
}

func TestTraceDatabase(t *testing.T) {
dbFile := path.Join(t.TempDir(), "test_db")
db, err := gorm.Open(sqlite.Open(dbFile))
if err != nil {
t.Fatalf("Failed to open DB: %s", err)
}

InstrumentDatabase(db, "test_app_name")
db = TraceDatabase(context.Background(), db)

if sp := db.Statement.Context.Value(parentSpanGormKey); sp == nil {
t.Error("Parent span not set on statement")
}
}

0 comments on commit 69dfa41

Please sign in to comment.