Skip to content

Commit fd3939f

Browse files
author
Ulrich Lissé
committed
Add error return value to NewApi()
1 parent 519c8f6 commit fd3939f

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

app/app.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ func NewApplication(fullConfigPath string) (*Application, error) {
3737
}
3838

3939
c := config.NewConfig(fullConfigPath)
40-
api := mite.NewApi(c.GetApiUrl(), c.GetApiKey(), version)
40+
api, err := mite.NewApi(c.GetApiUrl(), c.GetApiKey(), version)
41+
if err != nil {
42+
return nil, err
43+
}
4144

4245
if c.GetApiUrl() == "" {
4346
_, _ = fmt.Fprintln(os.Stderr, "please configure your API url by executing: 'mite config api.url=<your mite api url>'")

mite/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ type api struct {
2929
client *http.Client
3030
}
3131

32-
func NewApi(base string, key string, version string) Api {
32+
func NewApi(base string, key string, version string) (Api, error) {
3333
ua := fmt.Sprintf(userAgentTemplate, version)
34-
return &api{base: base, key: key, userAgent: ua, client: &http.Client{}}
34+
return &api{base: base, key: key, userAgent: ua, client: &http.Client{}}, nil
3535
}
3636

3737
func (a *api) get(resource string, result interface{}) error {

mite/project_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func TestApi_Projects(t *testing.T) {
5959

6060
defer srv.Close()
6161

62-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
62+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
63+
assert.Nil(t, err)
6364

6465
// when
6566
projects, err := api.Projects()

mite/service_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func TestApi_Services(t *testing.T) {
4545

4646
defer srv.Close()
4747

48-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
48+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
49+
assert.Nil(t, err)
4950

5051
// when
5152
services, err := api.Services()

mite/time_entry_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ func TestApi_TimeEntries(t *testing.T) {
8282

8383
defer srv.Close()
8484

85-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
85+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
86+
assert.Nil(t, err)
8687

8788
// when
8889
timeEntries, err := api.TimeEntries(nil)
@@ -113,7 +114,8 @@ func TestApi_TimeEntries_WithQuery(t *testing.T) {
113114

114115
defer srv.Close()
115116

116-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
117+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
118+
assert.Nil(t, err)
117119

118120
// when
119121
today := domain.Today()
@@ -150,7 +152,8 @@ func TestApi_TimeEntry(t *testing.T) {
150152

151153
defer srv.Close()
152154

153-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
155+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
156+
assert.Nil(t, err)
154157

155158
// when
156159
timeEntry, err := api.TimeEntry(timeEntryObject.Id)
@@ -186,7 +189,8 @@ func TestApi_CreateTimeEntry(t *testing.T) {
186189

187190
defer srv.Close()
188191

189-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
192+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
193+
assert.Nil(t, err)
190194

191195
// when
192196
command := &domain.TimeEntryCommand{
@@ -229,7 +233,8 @@ func TestApi_EditTimeEntry(t *testing.T) {
229233

230234
defer srv.Close()
231235

232-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
236+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
237+
assert.Nil(t, err)
233238

234239
// when
235240
command := &domain.TimeEntryCommand{
@@ -239,7 +244,7 @@ func TestApi_EditTimeEntry(t *testing.T) {
239244
ProjectId: timeEntryObject.ProjectId,
240245
ServiceId: timeEntryObject.ServiceId,
241246
}
242-
err := api.EditTimeEntry(timeEntryObject.Id, command)
247+
err = api.EditTimeEntry(timeEntryObject.Id, command)
243248

244249
// then
245250
assert.Nil(t, err)
@@ -265,10 +270,11 @@ func TestApi_DeleteTimeEntry(t *testing.T) {
265270

266271
defer srv.Close()
267272

268-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
273+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
274+
assert.Nil(t, err)
269275

270276
// when
271-
err := api.DeleteTimeEntry(timeEntryObject.Id)
277+
err = api.DeleteTimeEntry(timeEntryObject.Id)
272278

273279
// then
274280
assert.Nil(t, err)

mite/tracker_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ func TestApi_Tracker(t *testing.T) {
7373

7474
defer srv.Close()
7575

76-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
76+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
77+
assert.Nil(t, err)
7778

7879
// when
7980
tracking, err := api.Tracker()
@@ -104,7 +105,8 @@ func TestApi_Tracker_Empty(t *testing.T) {
104105

105106
defer srv.Close()
106107

107-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
108+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
109+
assert.Nil(t, err)
108110

109111
// when
110112
tracking, err := api.Tracker()
@@ -135,7 +137,8 @@ func TestApi_StartTracker(t *testing.T) {
135137

136138
defer srv.Close()
137139

138-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
140+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
141+
assert.Nil(t, err)
139142

140143
// when
141144
tracking, stopped, err := api.StartTracker(trackingTimeEntryObject.Id)
@@ -167,7 +170,8 @@ func TestApi_StartTracker_Running(t *testing.T) {
167170

168171
defer srv.Close()
169172

170-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
173+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
174+
assert.Nil(t, err)
171175

172176
// when
173177
tracking, stopped, err := api.StartTracker(trackingTimeEntryObject.Id)
@@ -199,7 +203,8 @@ func TestApi_StopTracker(t *testing.T) {
199203

200204
defer srv.Close()
201205

202-
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
206+
api, err := mite.NewApi(srv.URL, testApiKey, testClientVersion)
207+
assert.Nil(t, err)
203208

204209
// when
205210
stopped, err := api.StopTracker(stoppedTimeEntryObject.Id)

0 commit comments

Comments
 (0)