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.

58 lines
1.3 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. for _, row := range table {
  30. t.Run(row.Label, func(t *testing.T) {
  31. key := changekeys.One(row.Input)
  32. if key.ID != row.Output.ID || key.Model != row.Output.Model {
  33. t.Errorf("Incorrect: actual(%#+v, %#+v) != expected(%#+v, %#+v)", key.Model, key.ID, row.Output.Model, row.Output.ID)
  34. }
  35. })
  36. }
  37. }
  38. func BenchmarkOneHit(b *testing.B) {
  39. var post = models.Post{ID: "P123412341234123"}
  40. for n := 0; n < b.N; n++ {
  41. changekeys.One(post)
  42. }
  43. }
  44. func BenchmarkOneMiss(b *testing.B) {
  45. var story = models.Story{ID: "P123412341234123"}
  46. for n := 0; n < b.N; n++ {
  47. changekeys.One(story)
  48. }
  49. }