镜像自地址
https://github.com/tuna/tunasync.git
已同步 2025-12-06 14:36:47 +00:00
feature(worker): context object to store runtime configurations
这个提交包含在:
64
worker/context_test.go
普通文件
64
worker/context_test.go
普通文件
@@ -0,0 +1,64 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestContext(t *testing.T) {
|
||||
Convey("Context should work", t, func() {
|
||||
|
||||
ctx := NewContext()
|
||||
So(ctx, ShouldNotBeNil)
|
||||
So(ctx.parent, ShouldBeNil)
|
||||
|
||||
ctx.Set("logdir1", "logdir_value_1")
|
||||
ctx.Set("logdir2", "logdir_value_2")
|
||||
logdir, ok := ctx.Get("logdir1")
|
||||
So(ok, ShouldBeTrue)
|
||||
So(logdir, ShouldEqual, "logdir_value_1")
|
||||
|
||||
Convey("When entering a new context", func() {
|
||||
ctx = ctx.Enter()
|
||||
logdir, ok = ctx.Get("logdir1")
|
||||
So(ok, ShouldBeTrue)
|
||||
So(logdir, ShouldEqual, "logdir_value_1")
|
||||
|
||||
ctx.Set("logdir1", "new_value_1")
|
||||
|
||||
logdir, ok = ctx.Get("logdir1")
|
||||
So(ok, ShouldBeTrue)
|
||||
So(logdir, ShouldEqual, "new_value_1")
|
||||
|
||||
logdir, ok = ctx.Get("logdir2")
|
||||
So(ok, ShouldBeTrue)
|
||||
So(logdir, ShouldEqual, "logdir_value_2")
|
||||
|
||||
Convey("When accesing invalid key", func() {
|
||||
logdir, ok = ctx.Get("invalid_key")
|
||||
So(ok, ShouldBeFalse)
|
||||
So(logdir, ShouldBeNil)
|
||||
})
|
||||
|
||||
Convey("When exiting the new context", func() {
|
||||
ctx, err := ctx.Exit()
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
logdir, ok = ctx.Get("logdir1")
|
||||
So(ok, ShouldBeTrue)
|
||||
So(logdir, ShouldEqual, "logdir_value_1")
|
||||
|
||||
logdir, ok = ctx.Get("logdir2")
|
||||
So(ok, ShouldBeTrue)
|
||||
So(logdir, ShouldEqual, "logdir_value_2")
|
||||
|
||||
Convey("When exiting from top bottom context", func() {
|
||||
ctx, err := ctx.Exit()
|
||||
So(err, ShouldNotBeNil)
|
||||
So(ctx, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户