package changekeys_test import ( "testing" "git.aiterp.net/rpdata/api/models" "git.aiterp.net/rpdata/api/models/changekeys" ) func TestOne(t *testing.T) { table := []struct { Label string Input interface{} Output models.ChangeKey }{ { "Character_C17", models.Character{ID: "C17"}, models.ChangeKey{Model: "Character", ID: "C17"}, }, { "Channel_#Miner'sRespite", models.Channel{Name: "#Miner'sRespite"}, models.ChangeKey{Model: "Channel", ID: "#Miner'sRespite"}, }, { "Log_2018-10-23_210303325_RedrockAgency", models.Log{ID: "2018-10-23_210303325_RedrockAgency", ShortID: "L807"}, models.ChangeKey{Model: "Log", ID: "2018-10-23_210303325_RedrockAgency"}, }, } for _, row := range table { t.Run(row.Label, func(t *testing.T) { key := changekeys.One(row.Input) if key.ID != row.Output.ID || key.Model != row.Output.Model { t.Errorf("Incorrect: actual(%#+v, %#+v) != expected(%#+v, %#+v)", key.Model, key.ID, row.Output.Model, row.Output.ID) } }) } } func BenchmarkOneHit(b *testing.B) { var post = models.Post{ID: "P123412341234123"} for n := 0; n < b.N; n++ { changekeys.One(post) } } func BenchmarkOneMiss(b *testing.B) { var story = models.Story{ID: "P123412341234123"} for n := 0; n < b.N; n++ { changekeys.One(story) } }