-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
454 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
dist | ||
cmd/scripts/bindata | ||
cmd/bot1 | ||
*.cover | ||
cover.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,10 @@ import "os" | |
import "github.com/alaingilbert/ogame" | ||
|
||
func main() { | ||
universe := os.Getenv("UNIVERSE") | ||
username := os.Getenv("USERNAME") | ||
password := os.Getenv("PASSWORD") | ||
language := os.Getenv("LANGUAGE") | ||
universe := os.Getenv("UNIVERSE") // eg: Bellatrix | ||
username := os.Getenv("USERNAME") // eg: [email protected] | ||
password := os.Getenv("PASSWORD") // eg: ***** | ||
language := os.Getenv("LANGUAGE") // eg: en | ||
bot, _ := ogame.New(universe, username, password, language) | ||
attacked := bot.IsUnderAttack() | ||
fmt.Println(attacked) // False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ogame | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// RoundTripFunc . | ||
type RoundTripFunc func(req *http.Request) *http.Response | ||
|
||
// RoundTrip . | ||
func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { | ||
return f(req), nil | ||
} | ||
|
||
func TestOgameClient_Do(t *testing.T) { | ||
c := ogameClient{UserAgent: "test", Client: http.Client{Transport: RoundTripFunc(func(req *http.Request) *http.Response { | ||
// Test request parameters | ||
return &http.Response{ | ||
StatusCode: 200, | ||
// Send response to be tested | ||
Body: ioutil.NopCloser(bytes.NewBufferString(`OK`)), | ||
// Must be set to non-nil value or it panics | ||
Header: make(http.Header), | ||
} | ||
})}} | ||
req, _ := http.NewRequest("GET", "http://test.com", nil) | ||
_, err := c.Do(req) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "test", req.Header.Get("User-Agent")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ogame | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConstants_Speed_String(t *testing.T) { | ||
assert.Equal(t, "10%", Speed(1).String()) | ||
assert.Equal(t, "20%", Speed(2).String()) | ||
assert.Equal(t, "30%", Speed(3).String()) | ||
assert.Equal(t, "40%", Speed(4).String()) | ||
assert.Equal(t, "50%", Speed(5).String()) | ||
assert.Equal(t, "60%", Speed(6).String()) | ||
assert.Equal(t, "70%", Speed(7).String()) | ||
assert.Equal(t, "80%", Speed(8).String()) | ||
assert.Equal(t, "90%", Speed(9).String()) | ||
assert.Equal(t, "100%", Speed(10).String()) | ||
assert.Equal(t, "11", Speed(11).String()) | ||
} | ||
|
||
func TestConstants_MissionID_String(t *testing.T) { | ||
assert.Equal(t, "Attack", MissionID(1).String()) | ||
assert.Equal(t, "GroupedAttack", MissionID(2).String()) | ||
assert.Equal(t, "Transport", MissionID(3).String()) | ||
assert.Equal(t, "Park", MissionID(4).String()) | ||
assert.Equal(t, "ParkInThatAlly", MissionID(5).String()) | ||
assert.Equal(t, "Spy", MissionID(6).String()) | ||
assert.Equal(t, "Colonize", MissionID(7).String()) | ||
assert.Equal(t, "RecycleDebrisField", MissionID(8).String()) | ||
assert.Equal(t, "Destroy", MissionID(9).String()) | ||
assert.Equal(t, "MissileAttack", MissionID(10).String()) | ||
assert.Equal(t, "Expedition", MissionID(15).String()) | ||
assert.Equal(t, "16", MissionID(16).String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ogame | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDefence_String(t *testing.T) { | ||
r := DefensesInfos{ | ||
RocketLauncher: 1, | ||
LightLaser: 2, | ||
HeavyLaser: 3, | ||
GaussCannon: 4, | ||
IonCannon: 5, | ||
PlasmaTurret: 6, | ||
SmallShieldDome: 7, | ||
LargeShieldDome: 8, | ||
AntiBallisticMissiles: 9, | ||
InterplanetaryMissiles: 10, | ||
} | ||
expected := "\n" + | ||
" Rocket Launcher: 1\n" + | ||
" Light Laser: 2\n" + | ||
" Heavy Laser: 3\n" + | ||
" Gauss Cannon: 4\n" + | ||
" Ion Cannon: 5\n" + | ||
" Plasma Turret: 6\n" + | ||
" Small Shield Dome: 7\n" + | ||
" Large Shield Dome: 8\n" + | ||
"Anti Ballistic Missiles: 9\n" + | ||
"Interplanetary Missiles: 10" | ||
assert.Equal(t, expected, r.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ogame | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFacilities_ByID(t *testing.T) { | ||
f := Facilities{ | ||
RoboticsFactory: 1, | ||
Shipyard: 2, | ||
ResearchLab: 3, | ||
AllianceDepot: 4, | ||
MissileSilo: 5, | ||
NaniteFactory: 6, | ||
Terraformer: 7, | ||
SpaceDock: 8, | ||
} | ||
assert.Equal(t, 1, f.ByID(RoboticsFactoryID)) | ||
assert.Equal(t, 2, f.ByID(ShipyardID)) | ||
assert.Equal(t, 3, f.ByID(ResearchLabID)) | ||
assert.Equal(t, 4, f.ByID(AllianceDepotID)) | ||
assert.Equal(t, 5, f.ByID(MissileSiloID)) | ||
assert.Equal(t, 6, f.ByID(NaniteFactoryID)) | ||
assert.Equal(t, 7, f.ByID(TerraformerID)) | ||
assert.Equal(t, 8, f.ByID(SpaceDockID)) | ||
assert.Equal(t, 0, f.ByID(ID(12345))) | ||
} | ||
|
||
func TestFacilities_String(t *testing.T) { | ||
f := Facilities{ | ||
RoboticsFactory: 1, | ||
Shipyard: 2, | ||
ResearchLab: 3, | ||
AllianceDepot: 4, | ||
MissileSilo: 5, | ||
NaniteFactory: 6, | ||
Terraformer: 7, | ||
SpaceDock: 8, | ||
} | ||
expected := "\n" + | ||
"RoboticsFactory: 1\n" + | ||
" Shipyard: 2\n" + | ||
" Research Lab: 3\n" + | ||
" Alliance Depot: 4\n" + | ||
" Missile Silo: 5\n" + | ||
" Nanite Factory: 6\n" + | ||
" Terraformer: 7\n" + | ||
" Space Dock: 8" | ||
assert.Equal(t, expected, f.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ogame | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFleetID_String(t *testing.T) { | ||
assert.Equal(t, "12345", FleetID(12345).String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.