-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelite_test.go
167 lines (149 loc) · 4.25 KB
/
elite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package elite_test
import (
"fmt"
"testing"
"github.com/BenJuan26/elite"
)
var testLogPath = "./test"
func TestGetStatusFromBytes(t *testing.T) {
status, err := elite.GetStatusFromBytes([]byte(`{"timestamp":"2017-12-07T10:31:37Z", "event":"Status", "Flags":553713677, "Pips":[2,8,2], "FireGroup":0, "GuiFocus":5}`))
if err != nil {
fmt.Println("Couldn't get status: " + err.Error())
t.FailNow()
}
if !status.Flags.Docked ||
!status.Flags.ShieldsUp ||
!status.Flags.InMainShip ||
!status.Flags.LandingGearDown ||
!status.Flags.FSDMassLocked ||
!status.Flags.AltitudeFromAverageRadius {
fmt.Println("Parsed flags were incorrect")
t.FailNow()
}
if status.Flags.Landed ||
status.Flags.Supercruise ||
status.Flags.FlightAssistOff ||
status.Flags.HardpointsDeployed ||
status.Flags.InWing ||
status.Flags.LightsOn ||
status.Flags.CargoScoopDeployed ||
status.Flags.SilentRunning ||
status.Flags.ScoopingFuel ||
status.Flags.SRVHandbrake ||
status.Flags.SRVTurret ||
status.Flags.SRVUnderShip ||
status.Flags.SRVDriveAssist ||
status.Flags.FSDCharging ||
status.Flags.FSDCooldown ||
status.Flags.LowFuel ||
status.Flags.Overheating ||
status.Flags.HasLatLong ||
status.Flags.IsInDanger ||
status.Flags.BeingInterdicted ||
status.Flags.InFighter ||
status.Flags.InSRV ||
status.Flags.InAnalysisMode ||
status.Flags.NightVision ||
status.Flags.FSDJump ||
status.Flags.SRVHighBeam {
fmt.Println("Parsed flags were incorrect")
t.FailNow()
}
}
func TestGetStatusFromPath(t *testing.T) {
status, err := elite.GetStatusFromPath(testLogPath)
if err != nil {
fmt.Println("Couldn't get status: " + err.Error())
t.FailNow()
}
if !status.Flags.Docked ||
!status.Flags.ShieldsUp ||
!status.Flags.InMainShip ||
!status.Flags.LandingGearDown ||
!status.Flags.FSDMassLocked ||
!status.Flags.AltitudeFromAverageRadius {
fmt.Println("Parsed flags were incorrect")
t.FailNow()
}
if status.Flags.Landed ||
status.Flags.Supercruise ||
status.Flags.FlightAssistOff ||
status.Flags.HardpointsDeployed ||
status.Flags.InWing ||
status.Flags.LightsOn ||
status.Flags.CargoScoopDeployed ||
status.Flags.SilentRunning ||
status.Flags.ScoopingFuel ||
status.Flags.SRVHandbrake ||
status.Flags.SRVTurret ||
status.Flags.SRVUnderShip ||
status.Flags.SRVDriveAssist ||
status.Flags.FSDCharging ||
status.Flags.FSDCooldown ||
status.Flags.LowFuel ||
status.Flags.Overheating ||
status.Flags.HasLatLong ||
status.Flags.IsInDanger ||
status.Flags.BeingInterdicted ||
status.Flags.InFighter ||
status.Flags.InSRV ||
status.Flags.InAnalysisMode ||
status.Flags.NightVision ||
status.Flags.FSDJump ||
status.Flags.SRVHighBeam {
fmt.Println("Parsed flags were incorrect")
t.FailNow()
}
}
func TestGetStatus(t *testing.T) {
_, err := elite.GetStatus()
if err != nil {
fmt.Println("Couldn't get status: " + err.Error())
t.FailNow()
}
}
func TestGetStarSystemFromPath(t *testing.T) {
sys, err := elite.GetStarSystemFromPath(testLogPath)
if err != nil {
fmt.Println("An error occurred while getting the star system: " + err.Error())
t.FailNow()
}
if sys != "Sol" {
fmt.Println("Incorrect star system: Expecting Sol, got " + sys)
t.FailNow()
}
}
func TestGetLoadoutFromPath(t *testing.T) {
loadout, err := elite.GetLoadoutFromPath(testLogPath)
if err != nil {
fmt.Println("Couldn't get loadout: " + err.Error())
t.FailNow()
}
expectedShipName := "dora winifred"
if loadout.ShipName != expectedShipName {
fmt.Printf("Incorrect ship name: Expecting %s, got %s\n", expectedShipName, loadout.ShipName)
t.FailNow()
}
}
func TestGetStatisticsFromPath(t *testing.T) {
stats, err := elite.GetStatisticsFromPath(testLogPath)
if err != nil {
fmt.Println("Couldn't get statistics: " + err.Error())
t.FailNow()
}
expectedWealth := int64(951994467)
if stats.BankAccount.CurrentWealth != expectedWealth {
fmt.Printf("Incorrect wealth value: Expected %d, got %d\n", expectedWealth, stats.BankAccount.CurrentWealth)
}
}
func Example() {
// Errors not handled here
system, _ := elite.GetStarSystem()
fmt.Println("Current star system is " + system)
status, _ := elite.GetStatus()
if status.Flags.Docked {
fmt.Println("Ship is docked")
} else {
fmt.Println("Ship is not docked")
}
}