kctx_test.go 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package kctx
  2. import (
  3. "testing"
  4. )
  5. type tester struct {
  6. t *testing.T
  7. }
  8. func TestKernelCtx(t *testing.T) {
  9. sf := &tester{
  10. t: t,
  11. }
  12. sf.new()
  13. }
  14. // Создание контекста ядра
  15. func (sf *tester) new() {
  16. sf.t.Log("new")
  17. ctx := GetKernelCtx()
  18. if ctx == nil {
  19. sf.t.Fatalf("new(): KernelCtx==nil")
  20. }
  21. if ctx := ctx.CtxBg(); ctx != kernCtx.ctxBg {
  22. sf.t.Fatalf("new(): ctx!=ctxBg")
  23. }
  24. if ctx := ctx.BaseCtx(); ctx != kernCtx.ctx {
  25. sf.t.Fatalf("new(): ctx!=kernel.ctx")
  26. }
  27. ctx.Set("counter", 5, "test_counter")
  28. if ctx.Get("counter") == nil {
  29. sf.t.Fatalf("new(): counter==nil")
  30. }
  31. counter := ctx.Get("counter").Val().(int)
  32. if counter != 5 {
  33. sf.t.Fatalf("new(): counter(%v)!=5", counter)
  34. }
  35. ctx.Del("counter")
  36. ctx.Cancel()
  37. ctx.Done()
  38. ctx = GetKernelCtx()
  39. if ctx == nil {
  40. sf.t.Fatalf("new(): KernelCtx==nil")
  41. }
  42. if wg := ctx.Wg(); wg == nil {
  43. sf.t.Fatalf("new(): IKernelWg==nil")
  44. }
  45. if keep := ctx.Keeper(); keep == nil {
  46. sf.t.Fatalf("new(): IKernelKeeper==nil")
  47. }
  48. }