Commit 97ffc613 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 02dad3fa
......@@ -56,7 +56,7 @@ func currentTxn(ctx context.Context) Transaction {
// newTxn serves New.
func newTxn(ctx context.Context) (Transaction, context.Context) {
if getTxn(ctx) != nil {
panic("transaction: nested transactions are not supported")
panic("transaction: new: nested transactions not supported")
}
txn := &transaction{status: Active}
......
......@@ -12,3 +12,50 @@
// FOR A PARTICULAR PURPOSE.
package transaction
import (
"context"
"testing"
)
func TestBasic(t *testing.T) {
ctx := context.Background()
// Current(ø) -> panic
func() {
defer func() {
r := recover()
if r == nil {
t.Fatal("Current(ø) -> not paniced")
}
if want := "transaction: no current transaction"; r != want {
t.Fatalf("Current(ø) -> %q; want %q", r, want)
}
}()
Current(ctx)
}()
txn, ctx := New(ctx)
if txn_ := Current(ctx); txn_ != txn {
t.Fatalf("New inconsistent with Current: txn = %#v; txn_ = %#v", txn, txn_)
}
// subtransactions not allowed
func () {
defer func() {
r := recover()
if r == nil {
t.Fatal("New(!ø) -> not paniced")
}
if want := "transaction: new: nested transactions not supported"; r != want {
t.Fatalf("New(!ø) -> %q; want %q", r, want)
}
}()
_, _ = New(ctx)
}()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment