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.

63 lines
1.4 KiB

  1. package changekeys_test
  2. import (
  3. "testing"
  4. "git.aiterp.net/rpdata/api/models"
  5. "git.aiterp.net/rpdata/api/models/changekeys"
  6. )
  7. func TestOne(t *testing.T) {
  8. table := []struct {
  9. Label string
  10. Input interface{}
  11. Output models.ChangeKey
  12. }{
  13. {
  14. "Character_C17",
  15. models.Character{ID: "C17"},
  16. models.ChangeKey{Model: "Character", ID: "C17"},
  17. },
  18. {
  19. "Channel_#Miner'sRespite",
  20. models.Channel{Name: "#Miner'sRespite"},
  21. models.ChangeKey{Model: "Channel", ID: "#Miner'sRespite"},
  22. },
  23. {
  24. "Log_2018-10-23_210303325_RedrockAgency",
  25. models.Log{ID: "2018-10-23_210303325_RedrockAgency", ShortID: "L807"},
  26. models.ChangeKey{Model: "Log", ID: "2018-10-23_210303325_RedrockAgency"},
  27. },
  28. {
  29. "Comment_SCC1234",
  30. models.Comment{ID: "SCC1234"},
  31. models.ChangeKey{Model: "Comment", ID: "SCC1234"},
  32. },
  33. }
  34. for _, row := range table {
  35. t.Run(row.Label, func(t *testing.T) {
  36. key := changekeys.One(row.Input)
  37. if key.ID != row.Output.ID || key.Model != row.Output.Model {
  38. t.Errorf("Incorrect: actual(%#+v, %#+v) != expected(%#+v, %#+v)", key.Model, key.ID, row.Output.Model, row.Output.ID)
  39. }
  40. })
  41. }
  42. }
  43. func BenchmarkOneHit(b *testing.B) {
  44. var post = models.Post{ID: "P123412341234123"}
  45. for n := 0; n < b.N; n++ {
  46. changekeys.One(post)
  47. }
  48. }
  49. func BenchmarkOneMiss(b *testing.B) {
  50. var story = models.Story{ID: "P123412341234123"}
  51. for n := 0; n < b.N; n++ {
  52. changekeys.One(story)
  53. }
  54. }