Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
Update tests to use reflect.DeepEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmach committed May 30, 2014
1 parent a1d3b4b commit 1647157
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 302 deletions.
106 changes: 43 additions & 63 deletions activities_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package strava

import (
"reflect"
"testing"
"time"
)

func TestActivitiesGet(t *testing.T) {
// if you need to change this you should also update tests below
if c := structAttributeCount(&ActivityDetailed{}); c != 67 {
t.Fatalf("incorrect number of detailed attributes, %d != 67", c)
}

client := newCassetteClient(testToken, "activity_get")
activity, err := NewActivitiesService(client).Get(103221154).Do()

if err != nil {
t.Fatalf("service error: %v", err)
}

expected := &ActivityDetailed{}

expected.Id = 103221154
Expand All @@ -36,6 +37,8 @@ func TestActivitiesGet(t *testing.T) {

expected.StartDateString = "2010-08-15T18:04:29Z"
expected.StartDateLocalString = "2010-08-15T11:04:29Z"
expected.StartDate, _ = time.Parse(timeFormat, expected.StartDateString)
expected.StartDateLocal, _ = time.Parse(timeFormat, expected.StartDateLocalString)

expected.AchievementCount = 0
expected.KudosCount = 1
Expand Down Expand Up @@ -101,37 +104,33 @@ func TestActivitiesGet(t *testing.T) {
expected.SegmentEfforts[0].MovingTime = 113
expected.SegmentEfforts[0].StartDateString = "2010-08-15T18:23:07Z"
expected.SegmentEfforts[0].StartDateLocalString = "2010-08-15T11:23:07Z"
expected.SegmentEfforts[0].StartDate, _ = time.Parse(timeFormat, expected.SegmentEfforts[0].StartDateString)
expected.SegmentEfforts[0].StartDateLocal, _ = time.Parse(timeFormat, expected.SegmentEfforts[0].StartDateLocalString)
expected.SegmentEfforts[0].Distance = 805.6
expected.SegmentEfforts[0].StartIndex = 1112
expected.SegmentEfforts[0].EndIndex = 1225
expected.SegmentEfforts[0].Hidden = false

expected.SplitsMetric = make([]*Split, 0)
expected.SplitsStandard = make([]*Split, 0)
expected.BestEfforts = make([]*BestEffort, 0)

if err != nil {
t.Fatalf("service error: %v", err)
}

if activity.StartDate.IsZero() || activity.StartDateLocal.IsZero() {
t.Error("dates are not parsed")
}
expected.SplitsMetric = []*Split{}
expected.SplitsStandard = []*Split{}
expected.BestEfforts = []*BestEffort{}

if len(activity.SegmentEfforts) == 0 {
t.Fatal("no segment efforts!?!?!")
}

if activity.SegmentEfforts[0].StartDate.IsZero() || activity.SegmentEfforts[0].StartDateLocal.IsZero() {
t.Error("segment effort dates are not parsed")
if !reflect.DeepEqual(activity.SegmentEfforts[0], expected.SegmentEfforts[0]) {
t.Errorf("should match\n%v\n%v", activity.SegmentEfforts[0], expected.SegmentEfforts[0])
}

for _, prob := range structCompare(t, activity, expected) {
t.Error(prob)
}
// not comparing these here
activity.SegmentEfforts = expected.SegmentEfforts
activity.SplitsMetric = expected.SplitsMetric
activity.SplitsStandard = expected.SplitsStandard
activity.BestEfforts = expected.BestEfforts

for _, prob := range structCompare(t, activity.SegmentEfforts[0], expected.SegmentEfforts[0]) {
t.Error(prob)
if !reflect.DeepEqual(activity, expected) {
t.Errorf("should match\n%v\n%v", activity, expected)
}

// run
Expand Down Expand Up @@ -166,8 +165,8 @@ func TestActivitiesGet(t *testing.T) {
Split: 1,
}

for _, prob := range structCompare(t, split, activity.SplitsMetric[0]) {
t.Error(prob)
if !reflect.DeepEqual(activity.SplitsMetric[0], split) {
t.Errorf("should match\n%v\n%v", activity.SplitsMetric[0], split)
}

split = &Split{
Expand All @@ -178,8 +177,8 @@ func TestActivitiesGet(t *testing.T) {
Split: 1,
}

for _, prob := range structCompare(t, split, activity.SplitsStandard[0]) {
t.Error(prob)
if !reflect.DeepEqual(activity.SplitsStandard[0], split) {
t.Errorf("should match\n%v\n%v", activity.SplitsStandard[0], split)
}

bestEffort := &BestEffort{}
Expand All @@ -188,17 +187,21 @@ func TestActivitiesGet(t *testing.T) {
bestEffort.Name = "400m"
bestEffort.ElapsedTime = 111
bestEffort.MovingTime = 112

bestEffort.StartDateString = "2013-09-23T00:15:15Z"
bestEffort.StartDateLocalString = "2013-09-22T17:15:15Z"
bestEffort.StartDate, _ = time.Parse(timeFormat, bestEffort.StartDateString)
bestEffort.StartDateLocal, _ = time.Parse(timeFormat, bestEffort.StartDateLocalString)

bestEffort.Distance = 400
bestEffort.StartIndex = 1
bestEffort.EndIndex = 109

bestEffort.Activity.Id = 103359122
bestEffort.Athlete.Id = 227615

for _, prob := range structCompare(t, bestEffort, activity.BestEfforts[0]) {
t.Error(prob)
if !reflect.DeepEqual(activity.BestEfforts[0], bestEffort) {
t.Errorf("should match\n%v\n%v", activity.BestEfforts[0], bestEffort)
}

// hidden efforts
Expand Down Expand Up @@ -230,11 +233,6 @@ func TestActivitiesGet(t *testing.T) {
}

func TestActivitiesListComments(t *testing.T) {
// if you need to change this you should also update tests below
if c := structAttributeCount(&CommentSummary{}); c != 19 {
t.Fatalf("incorrect number of detailed attributes, %d != 19", c)
}

client := newCassetteClient(testToken, "activity_list_comments")
comments, err := NewActivitiesService(client).ListComments(103221154).Do()

Expand Down Expand Up @@ -351,11 +349,6 @@ func TestActivitiesListKudoers(t *testing.T) {
}

func TestActivitiesListPhotos(t *testing.T) {
// if you need to change this you should also update tests below
if c := structAttributeCount(&PhotoSummary{}); c != 9 {
t.Fatalf("incorrect number of detailed attributes, %d != 9", c)
}

// token for 3545423, I wasn't able to post a test photo for the other account
client := newCassetteClient("f578367dbb2288fb9f91090fa676111fdc5e8698", "activity_list_photos")
photos, err := NewActivitiesService(client).ListPhotos(103374194).Do()
Expand All @@ -378,13 +371,11 @@ func TestActivitiesListPhotos(t *testing.T) {
expected.Type = "InstagramPhoto"
expected.UploadedAtString = "2014-01-02T04:02:28Z"
expected.CreatedAtString = "2014-01-02T04:04:00Z"
expected.UploadedAt, _ = time.Parse(timeFormat, expected.UploadedAtString)
expected.CreatedAt, _ = time.Parse(timeFormat, expected.CreatedAtString)

if photos[0].CreatedAt.IsZero() || photos[0].UploadedAt.IsZero() {
t.Error("dates are not parsed")
}

for _, prob := range structCompare(t, photos[0], expected) {
t.Error(prob)
if !reflect.DeepEqual(photos[0], expected) {
t.Errorf("should match\n%v\n%v", photos[0], expected)
}

// from here on out just check the request parameters
Expand All @@ -404,11 +395,6 @@ func TestActivitiesListPhotos(t *testing.T) {
}

func TestActivitiesListZones(t *testing.T) {
// if you need to change this you should also update tests below
if c := structAttributeCount(&ZonesSummary{}); c != 9 {
t.Fatalf("incorrect number of detailed attributes, %d != 9", c)
}

client := newCassetteClient(testToken, "activity_list_zones")
zones, err := NewActivitiesService(client).ListZones(103221154).Do()

Expand Down Expand Up @@ -454,8 +440,8 @@ func TestActivitiesListZones(t *testing.T) {

expected := &ZoneBucket{Max: 143, Min: 108, Time: 910}

for _, prob := range structCompare(t, zones[0].Buckets[1], expected) {
t.Error(prob)
if !reflect.DeepEqual(zones[0].Buckets[1], expected) {
t.Errorf("should match\n%v\n%v", zones[0].Buckets[1], expected)
}

// from here on out just check the request parameters
Expand All @@ -475,11 +461,6 @@ func TestActivitiesListZones(t *testing.T) {
}

func TestActivitiesListLaps(t *testing.T) {
// if you need to change this you should also update tests below
if c := structAttributeCount(&LapEffortSummary{}); c != 19 {
t.Fatalf("incorrect number of detailed attributes, %d != 19", c)
}

client := newCassetteClient(testToken, "activity_list_laps")
laps, err := NewActivitiesService(client).ListLaps(103373338).Do()

Expand All @@ -500,8 +481,11 @@ func TestActivitiesListLaps(t *testing.T) {
expected.Name = "Lap 1"
expected.ElapsedTime = 6219
expected.MovingTime = 5118

expected.StartDateString = "2013-09-28T17:27:59Z"
expected.StartDateLocalString = "2013-09-28T10:27:59Z"
expected.StartDate, _ = time.Parse(timeFormat, expected.StartDateString)
expected.StartDateLocal, _ = time.Parse(timeFormat, expected.StartDateLocalString)

expected.Distance = 25109.4
expected.StartIndex = 0
Expand All @@ -513,12 +497,8 @@ func TestActivitiesListLaps(t *testing.T) {
expected.AveragePower = 70
expected.LapIndex = 1

for _, prob := range structCompare(t, laps[0], expected) {
t.Error(prob)
}

if laps[0].StartDate.IsZero() || laps[0].StartDateLocal.IsZero() {
t.Error("dates are not parsed")
if !reflect.DeepEqual(laps[0], expected) {
t.Errorf("should match\n%v\n%v", laps[0], expected)
}

// from here on out just check the request parameters
Expand Down
17 changes: 6 additions & 11 deletions athletes_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package strava

import (
"reflect"
"testing"
"time"
)

func TestAthletesGet(t *testing.T) {
// if you need to change this you should also update tests below
if c := structAttributeCount(&AthleteSummary{}); c != 15 {
t.Fatalf("incorrect number of detailed attributes, %d != 15", c)
}

client := newCassetteClient(testToken, "athlete_get")
athlete, err := NewAthletesService(client).Get(3545423).Do()

Expand All @@ -32,13 +29,11 @@ func TestAthletesGet(t *testing.T) {
expected.Gender = "M"
expected.CreatedAtString = "2013-12-26T19:19:36Z"
expected.UpdatedAtString = "2014-01-12T00:20:58Z"
expected.CreatedAt, _ = time.Parse(timeFormat, expected.CreatedAtString)
expected.UpdatedAt, _ = time.Parse(timeFormat, expected.UpdatedAtString)

if athlete.CreatedAt.IsZero() || athlete.UpdatedAt.IsZero() {
t.Error("segment effort dates are not parsed")
}

for _, prob := range structCompare(t, athlete, expected) {
t.Error(prob)
if !reflect.DeepEqual(athlete, expected) {
t.Errorf("should match\n%v\n%v", athlete, expected)
}

// from here on out just check the request parameters
Expand Down
18 changes: 7 additions & 11 deletions clubs_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package strava

import (
"reflect"
"testing"
)

func TestClubsGet(t *testing.T) {
// if you need to change this you should also update tests below
if c := structAttributeCount(&ClubDetailed{}); c != 12 {
t.Fatalf("incorrect number of detailed attributes, %d != 12", c)
}

client := newCassetteClient(testToken, "club_get")
club, err := NewClubsService(client).Get(45255).Do()

if err != nil {
t.Fatalf("service error: %v", err)
}

expected := &ClubDetailed{}
expected.Id = 45255
expected.Name = "Test Club"
Expand All @@ -27,12 +27,8 @@ func TestClubsGet(t *testing.T) {
expected.Private = true
expected.MemberCount = 2

if err != nil {
t.Fatalf("service error: %v", err)
}

for _, prob := range structCompare(t, club, expected) {
t.Error(prob)
if !reflect.DeepEqual(club, expected) {
t.Errorf("should match\n%v\n%v", club, expected)
}

// from here on out just check the request parameters
Expand Down
17 changes: 6 additions & 11 deletions current_athlete_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package strava

import (
"reflect"
"testing"
"time"
)

func TestCurrentAthleteGet(t *testing.T) {
// if you need to change this you should also update tests below
if c := structAttributeCount(&AthleteDetailed{}); c != 25 {
t.Fatalf("incorrect number of detailed attributes, %d != 25", c)
}

client := newCassetteClient(testToken, "current_athlete_get")
athlete, err := NewCurrentAthleteService(client).Get().Do()

Expand All @@ -30,6 +27,8 @@ func TestCurrentAthleteGet(t *testing.T) {
expected.Gender = "M"
expected.CreatedAtString = "2012-01-18T18:20:37Z"
expected.UpdatedAtString = "2014-01-21T06:23:32Z"
expected.CreatedAt, _ = time.Parse(timeFormat, expected.CreatedAtString)
expected.UpdatedAt, _ = time.Parse(timeFormat, expected.UpdatedAtString)
expected.Premium = true

expected.FollowerCount = 1
Expand Down Expand Up @@ -59,12 +58,8 @@ func TestCurrentAthleteGet(t *testing.T) {
expected.Shoes[0].Primary = true
expected.Shoes[0].Distance = 17224.6

if athlete.CreatedAt.IsZero() || athlete.UpdatedAt.IsZero() {
t.Error("segment effort dates are not parsed")
}

for _, prob := range structCompare(t, athlete, expected) {
t.Error(prob)
if !reflect.DeepEqual(athlete, expected) {
t.Errorf("should match\n%v\n%v", athlete, expected)
}

// from here on out just check the request parameters
Expand Down
14 changes: 5 additions & 9 deletions gear_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package strava

import (
"reflect"
"testing"
)

func TestGearGet(t *testing.T) {
// if you need to change this you should also update tests below
if c := structAttributeCount(&GearDetailed{}); c != 8 {
t.Fatalf("Gear: incorrect number of detailed attributes, %d != 8", c)
}

// bike
client := newCassetteClient(testToken, "gear_get_bike")
gear, err := NewGearService(client).Get("b77076").Do()
Expand All @@ -28,8 +24,8 @@ func TestGearGet(t *testing.T) {
t.Fatalf("Gear service error: %v", err)
}

for _, prob := range structCompare(t, gear, expected) {
t.Error(prob)
if !reflect.DeepEqual(gear, expected) {
t.Errorf("should match\n%v\n%v", gear, expected)
}

// shoe
Expand All @@ -49,8 +45,8 @@ func TestGearGet(t *testing.T) {
t.Fatalf("Gear service error: %v", err)
}

for _, prob := range structCompare(t, gear, expected) {
t.Error(prob)
if !reflect.DeepEqual(gear, expected) {
t.Errorf("should match\n%v\n%v", gear, expected)
}

// from here on out just check the request parameters
Expand Down
Loading

0 comments on commit 1647157

Please sign in to comment.