@@ -19,13 +19,15 @@ import (
19
19
func TestServer (t * testing.T ) {
20
20
t .Run ("foo create" , func (t * testing.T ) {
21
21
t .Run ("when provided a valid foo should pass" , func (t * testing.T ) {
22
- db := allsrv .ObserveDB ("inmem" , newTestMetrics (t ))(new (allsrv.InmemDB ))
23
- svr := allsrv .NewServer (db ,
22
+ met := newTestMetrics (t )
23
+ db := allsrv .ObserveDB ("inmem" , met )(new (allsrv.InmemDB ))
24
+ var svr http.Handler = allsrv .NewServer (db ,
24
25
allsrv .WithBasicAuth ("dodgers@stink.com" , "PaSsWoRd" ),
25
26
allsrv .WithIDFn (func () string {
26
27
return "id1"
27
28
}),
28
29
)
30
+ svr = allsrv .ObserveHandler ("allsrv" , met )(svr )
29
31
30
32
req := httptest .NewRequest ("POST" , "/foo" , newJSONBody (t , allsrv.Foo {
31
33
Name : "first-foo" ,
@@ -65,15 +67,17 @@ func TestServer(t *testing.T) {
65
67
66
68
t .Run ("foo read" , func (t * testing.T ) {
67
69
t .Run ("when querying for existing foo id should pass" , func (t * testing.T ) {
68
- db := allsrv .ObserveDB ("inmem" , newTestMetrics (t ))(new (allsrv.InmemDB ))
70
+ met := newTestMetrics (t )
71
+ db := allsrv .ObserveDB ("inmem" , met )(new (allsrv.InmemDB ))
69
72
err := db .CreateFoo (context .TODO (), allsrv.Foo {
70
73
ID : "reader1" ,
71
74
Name : "read" ,
72
75
Note : "another note" ,
73
76
})
74
77
require .NoError (t , err )
75
78
76
- svr := allsrv .NewServer (db , allsrv .WithBasicAuth ("dodgers@stink.com" , "PaSsWoRd" ))
79
+ var svr http.Handler = allsrv .NewServer (db , allsrv .WithBasicAuth ("dodgers@stink.com" , "PaSsWoRd" ))
80
+ svr = allsrv .ObserveHandler ("allsrv" , met )(svr )
77
81
78
82
req := httptest .NewRequest ("GET" , "/foo?id=reader1" , nil )
79
83
req .SetBasicAuth ("dodgers@stink.com" , "PaSsWoRd" )
@@ -107,15 +111,17 @@ func TestServer(t *testing.T) {
107
111
108
112
t .Run ("foo update" , func (t * testing.T ) {
109
113
t .Run ("when updating an existing foo with valid changes should pass" , func (t * testing.T ) {
110
- db := allsrv .ObserveDB ("inmem" , newTestMetrics (t ))(new (allsrv.InmemDB ))
114
+ met := newTestMetrics (t )
115
+ db := allsrv .ObserveDB ("inmem" , met )(new (allsrv.InmemDB ))
111
116
err := db .CreateFoo (context .TODO (), allsrv.Foo {
112
117
ID : "id1" ,
113
118
Name : "first_name" ,
114
119
Note : "first note" ,
115
120
})
116
121
require .NoError (t , err )
117
122
118
- svr := allsrv .NewServer (db , allsrv .WithBasicAuth ("dodgers@stink.com" , "PaSsWoRd" ))
123
+ var svr http.Handler = allsrv .NewServer (db , allsrv .WithBasicAuth ("dodgers@stink.com" , "PaSsWoRd" ))
124
+ svr = allsrv .ObserveHandler ("allsrv" , met )(svr )
119
125
120
126
req := httptest .NewRequest ("PUT" , "/foo" , newJSONBody (t , allsrv.Foo {
121
127
ID : "id1" ,
@@ -158,15 +164,17 @@ func TestServer(t *testing.T) {
158
164
159
165
t .Run ("foo delete" , func (t * testing.T ) {
160
166
t .Run ("when deleting an existing foo should pass" , func (t * testing.T ) {
161
- db := allsrv .ObserveDB ("inmem" , newTestMetrics (t ))(new (allsrv.InmemDB ))
167
+ met := newTestMetrics (t )
168
+ db := allsrv .ObserveDB ("inmem" , met )(new (allsrv.InmemDB ))
162
169
err := db .CreateFoo (context .TODO (), allsrv.Foo {
163
170
ID : "id1" ,
164
171
Name : "first_name" ,
165
172
Note : "first note" ,
166
173
})
167
174
require .NoError (t , err )
168
175
169
- svr := allsrv .NewServer (db , allsrv .WithBasicAuth ("dodgers@stink.com" , "PaSsWoRd" ))
176
+ var svr http.Handler = allsrv .NewServer (db , allsrv .WithBasicAuth ("dodgers@stink.com" , "PaSsWoRd" ))
177
+ svr = allsrv .ObserveHandler ("allsrv" , met )(svr )
170
178
171
179
req := httptest .NewRequest ("DELETE" , "/foo?id=id1" , nil )
172
180
req .SetBasicAuth ("dodgers@stink.com" , "PaSsWoRd" )
0 commit comments