| 33 | ) |
| 34 | |
| 35 | func TestPProf(t *testing.T) { |
| 36 | a := assertions.New(t) |
| 37 | |
| 38 | config := &Config{ |
| 39 | ServiceBase: config.ServiceBase{ |
| 40 | HTTP: config.HTTP{ |
| 41 | Listen: httpAddress, |
| 42 | Metrics: config.Metrics{ |
| 43 | Enable: true, |
| 44 | Password: metricsPassword, |
| 45 | }, |
| 46 | PProf: config.PProf{ |
| 47 | Enable: true, |
| 48 | Password: pprofPassword, |
| 49 | }, |
| 50 | Health: config.Health{ |
| 51 | Enable: true, |
| 52 | Password: healthPassword, |
| 53 | }, |
| 54 | }, |
| 55 | }, |
| 56 | } |
| 57 | c, err := New(test.GetLogger(t), config) |
| 58 | a.So(err, should.BeNil) |
| 59 | |
| 60 | err = c.listenWeb() |
| 61 | a.So(err, should.BeNil) |
| 62 | |
| 63 | client := &http.Client{} |
| 64 | |
| 65 | for _, tc := range []struct { |
| 66 | path string |
| 67 | username, password string |
| 68 | }{ |
| 69 | { |
| 70 | path: "debug/pprof", |
| 71 | username: pprofUsername, |
| 72 | password: pprofPassword, |
| 73 | }, |
| 74 | { |
| 75 | path: "metrics", |
| 76 | username: metricsUsername, |
| 77 | password: metricsPassword, |
| 78 | }, |
| 79 | { |
| 80 | path: "healthz", |
| 81 | username: healthUsername, |
| 82 | password: healthPassword, |
| 83 | }, |
| 84 | } { |
| 85 | t.Run(fmt.Sprintf("%s endpoint", tc.path), func(t *testing.T) { |
| 86 | a := assertions.New(t) |
| 87 | |
| 88 | url := fmt.Sprintf("http://%s/%s", httpAddress, tc.path) |
| 89 | res, err := client.Get(url) |
| 90 | if !a.So(err, should.BeNil) { |
| 91 | t.FailNow() |
| 92 | } |