ctx_value_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package ctx_value
  2. import (
  3. "testing"
  4. "gitp78su.ipnodns.ru/svi/kern/v4/d0"
  5. )
  6. type tester struct {
  7. t *testing.T
  8. val *CtxValue
  9. createdAt *d0.LTime
  10. owner *d0.LOwner
  11. }
  12. func TestCtxValue(t *testing.T) {
  13. sf := &tester{
  14. t: t,
  15. owner: d0.LetOwner(1, "test_ctx_value"),
  16. }
  17. sf.new()
  18. }
  19. // Создаёт значение локального контекста.
  20. func (sf *tester) new() {
  21. sf.t.Log("new")
  22. sf.val = NewCtxValue(sf.owner, "test_key", 5, "test_value")
  23. if sf.val == nil {
  24. sf.t.Fatalf("new(): val==nil")
  25. }
  26. if val := sf.val.Val().(d0.Num); val != 5 {
  27. sf.t.Fatalf("new(): val(%v)!=5", val)
  28. }
  29. createdAt := sf.val.CreateAt()
  30. if createdAt.Get() == "" {
  31. sf.t.Fatalf("new(): create is empty")
  32. }
  33. sf.createdAt = createdAt
  34. if comment := sf.val.Comment(); comment.Get() != "test_value" {
  35. sf.t.Fatalf("new(): comment(%v)!='test_value'", comment)
  36. }
  37. if key := sf.val.Key(); key.Get() != "test_key" {
  38. sf.t.Fatalf("new(): key(%v)!='test_key'", key)
  39. }
  40. if updatedAt := sf.val.UpdateAt(); updatedAt.Get() != "" {
  41. sf.t.Fatalf("new(): update not empty")
  42. }
  43. }