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.

151 lines
6.1 KiB

  1. package forumlog_test
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. "git.aiterp.net/rpdata/api/internal/importers/forumlog"
  7. "git.aiterp.net/rpdata/api/models"
  8. )
  9. func TestParseLogs(t *testing.T) {
  10. results, err := forumlog.ParseLogs(testLog, time.UTC)
  11. if err != nil {
  12. t.Fatalf("Parse: %s", err)
  13. }
  14. assert.Equal(t, 2, len(results), "Amount of results.")
  15. assert.Equal(t, testLogPosts[0], results[0].Posts, "First log's posts.")
  16. assert.Equal(t, testLogPosts[1], results[1].Posts, "Second log's posts.")
  17. }
  18. func TestParseLogsErrors(t *testing.T) {
  19. _, err1 := forumlog.ParseLogs(brokenLogNoPosts, time.UTC)
  20. _, err2 := forumlog.ParseLogs(brokenLogBrokenPost, time.UTC)
  21. _, err3 := forumlog.ParseLogs(brokenLogBrokenDate, time.UTC)
  22. t.Log("Should be about no posts:", err1)
  23. t.Log("Should be about a broken post:", err2)
  24. t.Log("Should be about a broken date:", err3)
  25. assert.NotEqual(t, err1, nil, "Should be no posts")
  26. assert.NotEqual(t, err2, nil, "Should be about a bad post")
  27. assert.NotEqual(t, err3, nil, "Should be about a broken date")
  28. }
  29. var testLog = `
  30. Date:
  31. July 25, 2013
  32. July 26, 2013
  33. GM:
  34. Tyranniac
  35. Length:
  36. 92 posts
  37. Characters:
  38. Fera'Sel nar Veltar - Baphomet
  39. Renala TIavay - Gisle
  40. Steven Briggs - Dante
  41. NPCs:
  42. Receptionist
  43. Relevant RPs:
  44. <-- Hub - Miner's Respite (July 16)
  45. --> Event - Hinpinn's Salvage Mission (August 5)
  46. [21:28] * @Tyranniac | The Hnipinn Minerals local administrative center is a rather small building located next to the refinery. The area is mostly asphalt and industrial surroundings. The gate in the fence surrounding the refinery is nearby, with a transport truck just being admitted by the guard - rather heavily armed for corporate security. Despite not being that late, it's rather dark due to the rain-bearing clouds that have just started emptying their content. The windows of the office glow with invitingly warm light. A receptionist can be seen working through the glass door.
  47. [21:46] * Steve_Briggs approaches the building at a brisk jog, pulling up the collar of his jacket to block as much of the rain as possible. Stopping just short of the door, he holds back and awaits Renala. "Well, hopefully this is the universe's way of getting our bad luck out of the way early." he says, glancing up at the sky. "Good things to come!" he adds with a smile.
  48. [21:46] * Steve_Briggs approaches the building at a brisk jog, pulling up the collar of his jacket to block as much of the rain as possible. Stopping just short of the door, he holds back and awaits Renala. "Well, hopefully this is the universe's way of getting our bad luck out of the way early." he says, glancing up at the sky. "Good things to come!" he adds with a smile.
  49. --> Stuff and things
  50. <-- Stuff and things
  51. [21:46] * Steve_Briggs approaches the building at a brisk jog, pulling up the collar of his jacket to block as much of the rain as possible. Stopping just short of the door, he holds back and awaits Renala. "Well, hopefully this is the universe's way of getting our bad luck out of the way early." he says, glancing up at the sky. "Good things to come!" he adds with a smile.
  52. `
  53. var testLogPosts = [][]models.Post{
  54. {
  55. {
  56. ID: "UNASSIGNED",
  57. LogID: "UNASSIGNED",
  58. Time: parseDate(nil, "2013-07-25 21:28:00"),
  59. Kind: "action",
  60. Nick: "Tyranniac",
  61. Text: "| The Hnipinn Minerals local administrative center is a rather small building located next to the refinery. The area is mostly asphalt and industrial surroundings. The gate in the fence surrounding the refinery is nearby, with a transport truck just being admitted by the guard - rather heavily armed for corporate security. Despite not being that late, it's rather dark due to the rain-bearing clouds that have just started emptying their content. The windows of the office glow with invitingly warm light. A receptionist can be seen working through the glass door.",
  62. Position: 1,
  63. },
  64. {
  65. ID: "UNASSIGNED",
  66. LogID: "UNASSIGNED",
  67. Time: parseDate(nil, "2013-07-25 21:46:00"),
  68. Kind: "action",
  69. Nick: "Steve_Briggs",
  70. Text: `approaches the building at a brisk jog, pulling up the collar of his jacket to block as much of the rain as possible. Stopping just short of the door, he holds back and awaits Renala. "Well, hopefully this is the universe's way of getting our bad luck out of the way early." he says, glancing up at the sky. "Good things to come!" he adds with a smile.`,
  71. Position: 2,
  72. },
  73. },
  74. {
  75. {
  76. ID: "UNASSIGNED",
  77. LogID: "UNASSIGNED",
  78. Time: parseDate(nil, "2013-07-26 21:46:00"),
  79. Kind: "action",
  80. Nick: "Steve_Briggs",
  81. Text: `approaches the building at a brisk jog, pulling up the collar of his jacket to block as much of the rain as possible. Stopping just short of the door, he holds back and awaits Renala. "Well, hopefully this is the universe's way of getting our bad luck out of the way early." he says, glancing up at the sky. "Good things to come!" he adds with a smile.`,
  82. Position: 1,
  83. },
  84. {
  85. ID: "UNASSIGNED",
  86. LogID: "UNASSIGNED",
  87. Time: parseDate(nil, "2013-07-26 21:46:00"),
  88. Kind: "action",
  89. Nick: "Steve_Briggs",
  90. Text: `approaches the building at a brisk jog, pulling up the collar of his jacket to block as much of the rain as possible. Stopping just short of the door, he holds back and awaits Renala. "Well, hopefully this is the universe's way of getting our bad luck out of the way early." he says, glancing up at the sky. "Good things to come!" he adds with a smile.`,
  91. Position: 2,
  92. },
  93. },
  94. }
  95. var brokenLogNoPosts = `
  96. Date:
  97. September 27, 2014
  98. `
  99. var brokenLogBrokenPost = `
  100. Date:
  101. September 10, 2038
  102. [12:38] * Some_Character is lasered by a reaper, and turns to ash before even knowing what happened.
  103. [12:4 * Some_Other_Character also meets the same fate, because the Reapers are no joke.
  104. `
  105. var brokenLogBrokenDate = `
  106. Date:
  107. 10 September, 2038
  108. [12:34] * =Scene= Stuff happens.
  109. `
  110. func parseDate(t *testing.T, date string) time.Time {
  111. result, err := time.Parse("2006-01-02 15:04:05", date)
  112. if err != nil {
  113. if t != nil {
  114. t.Fatal("Could not parse date", date, err)
  115. } else {
  116. panic("Could not parse date: " + err.Error())
  117. }
  118. }
  119. return result
  120. }