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. package logging
  17. import (
  18. "fmt"
  19. "strconv"
  20. "testing"
  21. )
  22. func empty() {
  23. }
  24. func TestGetGoID(t *testing.T) {
  25. for i := 0; i < 1000; i++ {
  26. goid := int(GetGoID())
  27. go empty()
  28. goid2 := int(GetGoID())
  29. if goid != goid2 {
  30. t.Errorf("%v, %v\n", goid, goid2)
  31. }
  32. }
  33. }
  34. func TestSeqid(t *testing.T) {
  35. logger, _ := BasicLogger("test")
  36. for i := 0; i < 1000; i++ {
  37. r := new(record)
  38. name := strconv.Itoa(i + 1)
  39. seq := logger.nextSeqid(r)
  40. if fmt.Sprintf("%d", seq) != name {
  41. t.Errorf("%v, %v\n", seq, name)
  42. }
  43. }
  44. logger.Destroy()
  45. }
  46. func TestName(t *testing.T) {
  47. name := "test"
  48. logger, _ := BasicLogger(name)
  49. r := new(record)
  50. if logger.lname(r) != name {
  51. t.Errorf("%v, %v\n", logger.lname(r), name)
  52. }
  53. logger.Destroy()
  54. }