| 40 | } |
| 41 | |
| 42 | func TestHTTPProvider_Success(t *testing.T) { |
| 43 | body := "overrides:\n user1:\n limit1: 100\n" |
| 44 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 45 | assert.Equal(t, "dskit-runtimeconfig", r.Header.Get("User-Agent")) |
| 46 | _, _ = w.Write([]byte(body)) |
| 47 | })) |
| 48 | defer srv.Close() |
| 49 | |
| 50 | p, _ := newTestHTTPProvider(t, srv.URL+"/config.yaml", &http.Client{}) |
| 51 | |
| 52 | data, err := p.Read(context.Background()) |
| 53 | require.NoError(t, err) |
| 54 | assert.Equal(t, body, string(data)) |
| 55 | assert.Equal(t, srv.URL+"/config.yaml", p.Name()) |
| 56 | |
| 57 | assert.Equal(t, 1, testutil.CollectAndCount(p.requestDuration)) |
| 58 | } |
| 59 | |
| 60 | func TestHTTPProvider_ServerError(t *testing.T) { |
| 61 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |