Exemplo n.º 1
0
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")
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
0
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)
}
Exemplo n.º 4
0
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())
}
Exemplo n.º 5
0
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())
}
Exemplo n.º 6
0
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()")

}
Exemplo n.º 7
0
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)
}
Exemplo n.º 8
0
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)
}
Exemplo n.º 9
0
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")))
}
Exemplo n.º 10
0
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)
}
Exemplo n.º 11
0
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")
}
Exemplo n.º 12
0
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)
}
Exemplo n.º 13
0
func TestSuccess(t *testing.T) {
  value := 5
  result := NewSuccess(value)

  assert.Equal(t, result.Success, value)
  assert.Nil(t, result.Failure)
}
Exemplo n.º 14
0
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)
}
Exemplo n.º 15
0
func TestDematerializeWithSuccess(t *testing.T) {
  result := NewSuccess(5)
  value, err := result.Dematerialize()

  assert.Equal(t, value, 5)
  assert.Nil(t, err)
}
Exemplo n.º 16
0
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")))
}
Exemplo n.º 17
0
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())")
}
Exemplo n.º 18
0
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")
}
Exemplo n.º 19
0
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)
}
Exemplo n.º 20
0
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")
}
Exemplo n.º 21
0
func TestFailure(t *testing.T) {
  err := &errorString{"testing error"}
  result := NewFailure(err)

  assert.Nil(t, result.Success)
  assert.Equal(t, result.Failure, err)
}
Exemplo n.º 22
0
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, "")
}
Exemplo n.º 23
0
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)
}
Exemplo n.º 24
0
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))
}
Exemplo n.º 25
0
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")
}
Exemplo n.º 26
0
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()")
}
Exemplo n.º 27
0
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)
}
Exemplo n.º 28
0
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)")
}
Exemplo n.º 29
0
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)
}
Exemplo n.º 30
0
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()))
}