fields_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2013, Cong Ding. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // author: Cong Ding <dinggnu@gmail.com>
  16. //
  17. package logging
  18. import (
  19. "fmt"
  20. "strconv"
  21. "testing"
  22. )
  23. func empty() {
  24. }
  25. func TestGetGoID(t *testing.T) {
  26. for i := 0; i < 1000; i++ {
  27. goid := int(GetGoID())
  28. go empty()
  29. goid2 := int(GetGoID())
  30. if goid != goid2 {
  31. t.Errorf("%v, %v\n", goid, goid2)
  32. }
  33. }
  34. }
  35. func TestSeqid(t *testing.T) {
  36. logger, _ := BasicLogger("test")
  37. for i := 0; i < 1000; i++ {
  38. r := new(record)
  39. name := strconv.Itoa(i + 1)
  40. seq := logger.nextSeqid(r)
  41. if fmt.Sprintf("%d", seq) != name {
  42. t.Errorf("%v, %v\n", seq, name)
  43. }
  44. }
  45. logger.Destroy()
  46. }
  47. func TestName(t *testing.T) {
  48. name := "test"
  49. logger, _ := BasicLogger(name)
  50. r := new(record)
  51. if logger.lname(r) != name {
  52. t.Errorf("%v, %v\n", logger.lname(r), name)
  53. }
  54. logger.Destroy()
  55. }