Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further clarify example test #271

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions example/weather/services/front/front_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestForecast(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, c.expectedResult, result)
assert.False(t, lmock.HasMore())
assert.False(t, fmock.HasMore())
})
}
}
Expand Down Expand Up @@ -77,10 +78,7 @@ var (

func getLocationInUSFunc(t *testing.T) mocklocator.ClientGetLocationFunc {
return func(ctx context.Context, ip string) (*locator.WorldLocation, error) {
if ip != testIP {
t.Errorf("GetLocation: got %s, expected %s", ip, testIP)
return nil, nil
}
assert.Equal(t, testIP, ip)
return &locator.WorldLocation{
Lat: testLocation.Lat,
Long: testLocation.Long,
Expand All @@ -93,10 +91,7 @@ func getLocationInUSFunc(t *testing.T) mocklocator.ClientGetLocationFunc {

func getLocationNotInUSFunc(t *testing.T) mocklocator.ClientGetLocationFunc {
return func(ctx context.Context, ip string) (*locator.WorldLocation, error) {
if ip != testIP {
t.Errorf("GetLocation: got %s, expected %s", ip, testIP)
return nil, nil
}
assert.Equal(t, testIP, ip)
return &locator.WorldLocation{
Lat: testLocation.Lat,
Long: testLocation.Long,
Expand All @@ -109,20 +104,15 @@ func getLocationNotInUSFunc(t *testing.T) mocklocator.ClientGetLocationFunc {

func getLocationErrorFunc(t *testing.T) mocklocator.ClientGetLocationFunc {
return func(ctx context.Context, ip string) (*locator.WorldLocation, error) {
if ip == "" {
t.Error("GetLocation: expected non-empty IP")
return nil, nil
}
assert.NotEmpty(t, ip)
return nil, errLocation
}
}

func getForecastFunc(t *testing.T) mockforecaster.ClientGetForecastFunc {
return func(ctx context.Context, lat float64, long float64) (*forecaster.Forecast, error) {
if lat != testLocation.Lat || long != testLocation.Long {
t.Errorf("GetForecast: expected (%f, %f), got (%f, %f)", testLocation.Lat, testLocation.Long, lat, long)
return nil, nil
}
assert.Equal(t, testLocation.Lat, lat)
assert.Equal(t, testLocation.Long, long)
lval := forecaster.Location(*testForecast.Location)
ps := make([]*forecaster.Period, len(testForecast.Periods))
for i, p := range testForecast.Periods {
Expand Down
Loading