func TestGetGamesByIDS(t *testing.T) { print("GetGamesByIDs\n") seedGame() user := gu(t) g, err := GetGame(1, user) assert.Nil(t, err, "GetGame(1,user)") g.EbayURL = "My Url" g.EbayEnds = "2017-06-22 20:41:25" g.EbayPrice = 4.32 g.EbayUpdated = "2016-06-22 20:41:25" err = g.Save() assert.Nil(t, err, "g.Save()") idl := []int{1, 2, 3, 4, 5} gl, err := GetGamesByIDS(idl, user) assert.Nil(t, err, "GetGamesByIDS(idl,user)") assert.Equal(t, 2, len(gl), "len(gamelist)") g = gl[0] assert.Equal(t, 1, g.User.ID, "g.User.ID") assert.Equal(t, "game1", g.Name, "g.Name") assert.Equal(t, "Nintendo", g.Publisher, "g.Publisher") assert.Equal(t, 1990, g.Year, "g.Year") assert.Equal(t, true, g.Has, "g.Has") assert.Equal(t, true, g.HasBox, "g.HasBox") assert.Equal(t, true, g.HasManual, "g.HasManual") assert.Equal(t, 3, g.Rating, "g.Rating") assert.Equal(t, "is good", g.Review, "g.Review") assert.Equal(t, false, g.Want, "Want") assert.Equal(t, "2016-06-22 20:41:25", g.EbayUpdated, "g.EbayUpdated") assert.Equal(t, 4.32, g.EbayPrice, "g.EbayPrice") assert.Equal(t, "My Url", g.EbayURL, "g.EbayUrl") assert.Equal(t, "2017-06-22 20:41:25", g.EbayEnds, "g.EbayEnds") }
func TestConsole_CheapestGame(t *testing.T) { print("Console.CheapestGame\n") seedConsole() user, err := auth.GetUser(1) if err != nil { t.Errorf("GetUser(1): %s", err) } c, err := GetConsole("NES", user) assert.Nil(t, err, "GetConsole(NES,user)") c.WantGames = true c.Save() p := 1.01 gl, err := c.WantedGames() fmt.Printf("len(wantedgames): %v\n", len(gl)) assert.Nil(t, err, "c.Games()") for _, g := range gl { g.EbayPrice = p g.Want = true p = p + 1.01 g.EbayEnds = "2999-01-01 01:00:00" err := g.Save() assert.Nil(t, err, "g.Save()") } d, err := GetConsole("NES", user) if err != nil { t.Errorf("GetConsole(NES,user): %s", err) } g := d.CheapestGame() assert.Equal(t, 1.01, g.EbayPrice, "EbayPrice") fmt.Printf("%s, %.2v\n", g.Name, g.EbayPrice) }
func TestNewCommentID(t *testing.T) { c, err := NewComment("This behavior is undocumented", "abcdefg", nil, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Nil(t, comment.ID) }
func TestEntry_ViewMode(t *testing.T) { e := ef() assert.Equal(t, "default", e.ViewMode(), "initial entry.ViewMode") f, err := GetFeed(1) assert.Nil(t, err, "GetFeed(1)") f.ViewMode = "link" err = f.Save() assert.Nil(t, err) assert.Equal(t, "link", e.ViewMode()) }
func TestEntry_AutoscrollPX(t *testing.T) { e := ef() assert.Equal(t, 0, e.AutoscrollPX()) f, err := GetFeed(1) assert.Nil(t, err) f.AutoscrollPX = 1234 err = f.Save() assert.Nil(t, err) assert.Equal(t, 1234, e.AutoscrollPX()) }
func TestGetAllWantedGames(t *testing.T) { print("GetAllWantedGames\n") seedGame() user := gu(t) c, err := GetConsole("Atari 2600", user) assert.Nil(t, err, "GetConsole(Atari 2600,user)") c2, err := GetConsole("NES", user) assert.Nil(t, err, "GetConsole(NES,user)") print("\tInitial\n") wg, err := GetAllWantedGames() assert.Nil(t, err, "GetAllWantedGames()") assert.Equal(t, 0, len(wg), "GetAllWantedGames") print("\tMarking individual games\n") g, err := GetGame(1, user) assert.Nil(t, err, "GetGame(1,user)") g.Want = true err = g.Save() assert.Nil(t, err, "g.Save()") wg, err = GetAllWantedGames() assert.Nil(t, err, "GetAllWantedGames()") assert.Equal(t, 1, len(wg), "GetAllWantedGames()") print("\tMarking Console WantGames\n") c.WantGames = true err = c.Save() assert.Nil(t, err, "c.Save()") c2.WantGames = true err = c2.Save() assert.Nil(t, err, "c2.Save()") wg, err = GetAllWantedGames() assert.Nil(t, err, "GetAllWantedGames()") assert.Equal(t, 1321, len(wg), "GetAllWantedGames()") }
func TestEntry_UnMark(t *testing.T) { e := ef() err := e.Mark() assert.Nil(t, err) e = ge() assert.Equal(t, "1", e.Marked) err = e.UnMark() assert.Nil(t, err) e = ge() assert.Equal(t, "0", e.Marked) }
func TestEntry_MarkUnread(t *testing.T) { e := ef() err := e.MarkRead() assert.Nil(t, err) e = ge() assert.False(t, e.Unread) err = e.MarkUnread() assert.Nil(t, err) e = ge() assert.True(t, e.Unread) }
func TestCategory_SearchTitles(t *testing.T) { seed() c1 := GetCat("1") assert.Equal(t, 2, len(c1.SearchTitles("asdf", "unread"))) assert.Equal(t, 2, len(c1.SearchTitles("asdf", "all"))) e1 := GetEntry("1", "test") err := e1.MarkRead() assert.Nil(t, err) assert.Equal(t, 1, len(c1.SearchTitles("asdf", "read"))) err = e1.Mark() assert.Nil(t, err) assert.Equal(t, 1, len(c1.SearchTitles("asdf", "marked"))) }
func TestEntry_ToggleMark(t *testing.T) { e := ef() nm, err := e.ToggleMark() assert.Nil(t, err) assert.Equal(t, "set", nm) e = ge() assert.Equal(t, "1", e.Marked) assert.Nil(t, err) nm, err = e.ToggleMark() assert.Equal(t, "unset", nm) assert.Nil(t, err) e = ge() assert.Equal(t, "0", e.Marked) }
func TestGetGamesByConsole(t *testing.T) { print("GetGamesByConsole\n") c := gsc(t) gl, err := GetGamesByConsole(c) assert.Nil(t, err, "GetGamesByConsole()") assert.Equal(t, 801, len(gl), "GetGamesByConsole") }
func TestFlatMapOnSuccessReturnsNewValue(t *testing.T) { result := NewSuccess(5) resultantResult := result.FlatMap(func(value interface{}) Result { return NewSuccess(value.(int) * 2) }) assert.Equal(t, resultantResult.Success, 10) assert.Nil(t, resultantResult.Failure) }
func TestSuccess(t *testing.T) { value := 5 result := NewSuccess(value) assert.Equal(t, result.Success, value) assert.Nil(t, result.Failure) }
func TestCompareVersionsRepoCorrupted(t *testing.T) { status, err := compareVersion("1.4.5", "2.0").Dematerialize() assert.NotNil(t, err) assert.True(t, strings.Contains(err.Error(), "1.4.5")) assert.True(t, strings.Contains(err.Error(), "2.0")) assert.Nil(t, status) }
func TestDematerializeWithSuccess(t *testing.T) { result := NewSuccess(5) value, err := result.Dematerialize() assert.Equal(t, value, 5) assert.Nil(t, err) }
func TestAllMarkedEntries(t *testing.T) { e := ef() assert.Equal(t, 0, len(AllMarkedEntries("test"))) err := e.Mark() assert.Nil(t, err) assert.Equal(t, 1, len(AllMarkedEntries("test"))) }
func TestAllUsers(t *testing.T) { initTest(t) print("AllUsers\n") ul, err := AllUsers() assert.Nil(t, err, "AllUsers()") assert.Equal(t, len(ul), 12, "len(AllUsers())") }
func TestNewCommentContent(t *testing.T) { c, err := NewComment("Season the chex mix", "abcdefg", nil, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Equal(t, comment.Content, "Season the chex mix") }
func TestNewCommentDeleted(t *testing.T) { c, err := NewComment("What is happening here?", "abcdefg", nil, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.False(t, comment.Deleted) }
func TestNewCommentCommit(t *testing.T) { c, err := NewComment("Wat?", "abcdefg", nil, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Equal(t, *comment.Commit, "abcdefg") }
func TestFailure(t *testing.T) { err := &errorString{"testing error"} result := NewFailure(err) assert.Nil(t, result.Success) assert.Equal(t, result.Failure, err) }
func TestCreatePersonWithoutName(t *testing.T) { p, err := CreatePerson("<*****@*****.**>").Dematerialize() assert.Nil(t, err) person := p.(*Person) assert.NotNil(t, person) assert.Equal(t, person.Email, "*****@*****.**") assert.Equal(t, person.Name, "") }
func TestSerializePersonFull(t *testing.T) { data := "Katie Em <*****@*****.**> 1437498360 +0400" p, err := CreatePerson(data).Dematerialize() assert.Nil(t, err) assert.NotNil(t, p) person := p.(*Person) assert.Equal(t, person.Serialize(), data) }
func TestSerializePersonEmailOnly(t *testing.T) { data := "<*****@*****.**>" p, err := CreatePerson(data).Dematerialize() assert.Nil(t, err) assert.NotNil(t, p) person := p.(*Person) assert.True(t, strings.Contains(person.Serialize(), data)) }
func TestCreatePersonFromNameEmailTime(t *testing.T) { p, err := CreatePerson("Carrie <*****@*****.**> 1437612685 -0700").Dematerialize() assert.Nil(t, err) person := p.(*Person) assert.NotNil(t, person) assert.Equal(t, person.Email, "*****@*****.**") assert.Equal(t, person.Name, "Carrie") }
func TestGame_Price(t *testing.T) { print("Game.Price()\n") g := gg(t) g.EbayPrice = 3.333333 err := g.Save() assert.Nil(t, err, "g.Save()") assert.Equal(t, "3.33", g.Price(), "g.Price()") }
func TestNewCommentFileRef(t *testing.T) { ref := &FileRef{"src/example.c", 12, RefLineTypeNew} c, err := NewComment("This should be more modular", "abcdefg", ref, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Equal(t, comment.FileRef, ref) }
func TestFilter_Manual(t *testing.T) { print("Filter_Manual\n") c := gsc(t) gl, err := c.Games() assert.Nil(t, err, "c.Games()") assert.Equal(t, 1, len(Filter(gl).Manual(true)), "FilterManual(true)") assert.Equal(t, 800, len(Filter(gl).Manual(false)), "FilterManual(false)") }
func TestNewCommentAmender(t *testing.T) { author := &Person{"Sam Wafers", "<*****@*****.**>", time.Now(), "-0600"} c, err := NewComment("Doesn't this violate the laws of physics?", "123", nil, author).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Equal(t, comment.Amender, author) }
func TestCategory_MarkEntriesRead(t *testing.T) { seed() c1 := GetCat("1") el := []string{"1", "2"} err := c1.MarkEntriesRead(el) assert.Nil(t, err) assert.Equal(t, 2, len(c1.UnreadEntries())) }