Skip to content

Commit

Permalink
adjust tests and Stringer
Browse files Browse the repository at this point in the history
  • Loading branch information
redradrat committed Nov 26, 2021
1 parent 83b44c5 commit ea558f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 10 additions & 1 deletion speedtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,23 @@ func (l Servers) FindServer(serverID []int) (Servers, error) {
}

// String representation of ServerList
func (l *ServerList) String() string {
func (l ServerList) String() string {
slr := ""
for _, s := range l.Servers {
slr += s.String()
}
return slr
}

// String representation of Servers
func (l Servers) String() string {
slr := ""
for _, s := range l {
slr += s.String()
}
return slr
}

// String representation of Server
func (s *Server) String() string {
return fmt.Sprintf("[%4s] %8.2fkm \n%s (%s) by %s\n", s.ID, s.Distance, s.Name, s.Country, s.Sponsor)
Expand Down
17 changes: 8 additions & 9 deletions speedtest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ func TestFetchServerList(t *testing.T) {
Lon: "138.44",
Isp: "Hello",
}
serverList, err := FetchServers(&user)
servers, err := FetchServers(&user)
if err != nil {
t.Errorf(err.Error())
}
if len(serverList.Servers) == 0 {
if len(servers) == 0 {
t.Errorf("Failed to fetch server list.")
}
if len(serverList.Servers[0].Country) == 0 {
t.Errorf("got unexpected country name '%v'", serverList.Servers[0].Country)
if len(servers[0].Country) == 0 {
t.Errorf("got unexpected country name '%v'", servers[0].Country)
}
}

Expand Down Expand Up @@ -45,7 +45,7 @@ func TestDistance(t *testing.T) {
}

func TestFindServer(t *testing.T) {
servers := []*Server{
servers := Servers{
&Server{
ID: "1",
},
Expand All @@ -56,10 +56,9 @@ func TestFindServer(t *testing.T) {
ID: "3",
},
}
serverList := ServerList{Servers: servers}

serverID := []int{}
s, err := serverList.FindServer(serverID)
s, err := servers.FindServer(serverID)
if err != nil {
t.Errorf(err.Error())
}
Expand All @@ -71,7 +70,7 @@ func TestFindServer(t *testing.T) {
}

serverID = []int{2}
s, err = serverList.FindServer(serverID)
s, err = servers.FindServer(serverID)
if err != nil {
t.Errorf(err.Error())
}
Expand All @@ -83,7 +82,7 @@ func TestFindServer(t *testing.T) {
}

serverID = []int{3, 1}
s, err = serverList.FindServer(serverID)
s, err = servers.FindServer(serverID)
if err != nil {
t.Errorf(err.Error())
}
Expand Down

0 comments on commit ea558f7

Please sign in to comment.