Skip to content

Commit

Permalink
Merge branch 'release/1.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Sep 13, 2018
2 parents 04e427a + c825f82 commit 989b54d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1661,9 +1661,11 @@ func extractGalaxyInfos(pageHTML, botPlayerName string, botPlayerID, botPlayerRa
activity := 0
activityDiv := s.Find("div.activity")
if activityDiv != nil {
activityRaw := strings.TrimSpace(activityDiv.Text())
if activityRaw != "" {
activity, _ = strconv.Atoi(activityRaw)
activityDivClass := activityDiv.AttrOr("class", "")
if strings.Contains(activityDivClass, "minute15") {
activity = 15
} else if strings.Contains(activityDivClass, "showMinutes") {
activity, _ = strconv.Atoi(strings.TrimSpace(activityDiv.Text()))
}
}

Expand Down
21 changes: 21 additions & 0 deletions ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ func TestExtractGalaxyInfosOwnPlanet(t *testing.T) {
assert.Equal(t, "Homeworld", infos[4].Name)
}

func TestExtractGalaxyInfosPlanetNoActivity(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_planet_activity.html")
infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456)
assert.Equal(t, 8, len(infos))
assert.Equal(t, 0, infos[7].Activity)
}

func TestExtractGalaxyInfosPlanetActivity15(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_planet_activity.html")
infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456)
assert.Equal(t, 8, len(infos))
assert.Equal(t, 15, infos[2].Activity)
}

func TestExtractGalaxyInfosPlanetActivity23(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_planet_activity.html")
infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456)
assert.Equal(t, 8, len(infos))
assert.Equal(t, 23, infos[3].Activity)
}

func TestExtractGalaxyInfosMoonActivity(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_moon_activity.html")
infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456)
Expand Down
1 change: 1 addition & 0 deletions samples/galaxy_planet_activity.html

Large diffs are not rendered by default.

0 comments on commit 989b54d

Please sign in to comment.