GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.7 KiB

  1. package changekeys_test
  2. import (
  3. "testing"
  4. "git.aiterp.net/rpdata/api/models/changekeys"
  5. "git.aiterp.net/rpdata/api/models"
  6. )
  7. func TestMany(t *testing.T) {
  8. data := []interface{}{
  9. models.Log{ID: "Stuff"},
  10. []interface{}{
  11. models.Post{ID: "P1"},
  12. models.Post{ID: "P2"},
  13. models.Post{ID: "P3"},
  14. []interface{}{
  15. models.Post{ID: "P4"},
  16. models.Character{ID: "C17"},
  17. models.Channel{Name: "#Stuff"},
  18. },
  19. },
  20. models.Post{ID: "P5"},
  21. models.Comment{ID: "SCC1234"},
  22. }
  23. expectations := []models.ChangeKey{
  24. {Model: "Log", ID: "Stuff"},
  25. {Model: "Post", ID: "P1"},
  26. {Model: "Post", ID: "P2"},
  27. {Model: "Post", ID: "P3"},
  28. {Model: "Post", ID: "P4"},
  29. {Model: "Character", ID: "C17"},
  30. {Model: "Channel", ID: "#Stuff"},
  31. {Model: "Post", ID: "P5"},
  32. {Model: "Comment", ID: "SCC1234"},
  33. }
  34. results := changekeys.Many(data...)
  35. if len(results) != len(expectations) {
  36. t.Fatal("Incorrect result length")
  37. }
  38. for i := range expectations {
  39. result := results[i]
  40. expectation := expectations[i]
  41. if result.ID != expectation.ID || result.Model != expectation.Model {
  42. t.Errorf("Incorrect: actual(%#+v, %#+v) != expected(%#+v, %#+v)", result.Model, result.ID, expectation.Model, expectation.ID)
  43. }
  44. }
  45. }
  46. func BenchmarkMany(b *testing.B) {
  47. data := []interface{}{
  48. models.Log{ID: "Stuff"},
  49. []interface{}{
  50. models.Post{ID: "P1"},
  51. models.Post{ID: "P2"},
  52. models.Post{ID: "P3"},
  53. models.Post{ID: "P4"},
  54. models.Post{ID: "P5"},
  55. models.Post{ID: "P6"},
  56. models.Post{ID: "P7"},
  57. models.Post{ID: "P8"},
  58. models.Post{ID: "P9"},
  59. models.Post{ID: "P10"},
  60. models.Post{ID: "P11"},
  61. },
  62. models.Character{ID: "C17"},
  63. models.Channel{Name: "#Stuff"},
  64. }
  65. b.ResetTimer()
  66. for n := 0; n < b.N; n++ {
  67. changekeys.Many(data...)
  68. }
  69. }