|
|
package forumlog_test
import ( "testing" "time"
"github.com/stretchr/testify/assert"
"git.aiterp.net/rpdata/api/internal/importers/forumlog"
"git.aiterp.net/rpdata/api/models" )
func TestParseLogs(t *testing.T) { results, err := forumlog.ParseLogs(testLog, time.UTC) if err != nil { t.Fatalf("Parse: %s", err) }
assert.Equal(t, 2, len(results), "Amount of results.") assert.Equal(t, testLogPosts[0], results[0].Posts, "First log's posts.") assert.Equal(t, testLogPosts[1], results[1].Posts, "Second log's posts.") }
func TestParseLogsErrors(t *testing.T) { _, err1 := forumlog.ParseLogs(brokenLogNoPosts, time.UTC) _, err2 := forumlog.ParseLogs(brokenLogBrokenPost, time.UTC) _, err3 := forumlog.ParseLogs(brokenLogBrokenDate, time.UTC)
t.Log("Should be about no posts:", err1) t.Log("Should be about a broken post:", err2) t.Log("Should be about a broken date:", err3)
assert.NotEqual(t, err1, nil, "Should be no posts") assert.NotEqual(t, err2, nil, "Should be about a bad post") assert.NotEqual(t, err3, nil, "Should be about a broken date") }
var testLog = ` Date: July 25, 2013 July 26, 2013
GM: Tyranniac
Length: 92 posts
Characters: Fera'Sel nar Veltar - Baphomet Renala T’Iavay - Gisle Steven Briggs - Dante
NPCs: Receptionist
Relevant RPs: <-- Hub - Miner's Respite (July 16) --> Event - Hinpinn's Salvage Mission (August 5)
[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.
[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.
[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.
--> Stuff and things
<-- Stuff and things
[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. `
var testLogPosts = [][]models.Post{ { { ID: "UNASSIGNED", LogID: "UNASSIGNED", Time: parseDate(nil, "2013-07-25 21:28:00"), Kind: "action", Nick: "Tyranniac", 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.", Position: 1, }, { ID: "UNASSIGNED", LogID: "UNASSIGNED", Time: parseDate(nil, "2013-07-25 21:46:00"), Kind: "action", Nick: "Steve_Briggs", 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.`, Position: 2, }, }, { { ID: "UNASSIGNED", LogID: "UNASSIGNED", Time: parseDate(nil, "2013-07-26 21:46:00"), Kind: "action", Nick: "Steve_Briggs", 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.`, Position: 1, }, { ID: "UNASSIGNED", LogID: "UNASSIGNED", Time: parseDate(nil, "2013-07-26 21:46:00"), Kind: "action", Nick: "Steve_Briggs", 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.`, Position: 2, }, }, }
var brokenLogNoPosts = ` Date: September 27, 2014 `
var brokenLogBrokenPost = ` Date: September 10, 2038
[12:38] * Some_Character is lasered by a reaper, and turns to ash before even knowing what happened.
[12:4 * Some_Other_Character also meets the same fate, because the Reapers are no joke. `
var brokenLogBrokenDate = ` Date: 10 September, 2038
[12:34] * =Scene= Stuff happens. `
func parseDate(t *testing.T, date string) time.Time { result, err := time.Parse("2006-01-02 15:04:05", date) if err != nil { if t != nil { t.Fatal("Could not parse date", date, err) } else { panic("Could not parse date: " + err.Error()) } }
return result }
|