use testhttp instead of http for ut (#585)
* use testhttp instead of http for ut * bugfix: add username check
This commit is contained in:
parent
417a13c1be
commit
322cbf27dc
src/modules
|
@ -1,11 +1,10 @@
|
|||
package prometheus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/didi/nightingale/src/common/dataobj"
|
||||
"github.com/didi/nightingale/src/modules/prober/manager"
|
||||
|
@ -48,17 +47,11 @@ test_guauge{label="3"} 1.3
|
|||
`
|
||||
|
||||
func TestCollect(t *testing.T) {
|
||||
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, sampleTextFormat) })
|
||||
server := &http.Server{Addr: ":18080"}
|
||||
go func() {
|
||||
server.ListenAndServe()
|
||||
}()
|
||||
defer server.Shutdown(context.Background())
|
||||
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, sampleTextFormat) }))
|
||||
defer s.Close()
|
||||
|
||||
PluginTest(t, &PrometheusRule{
|
||||
URLs: []string{"http://localhost:18080/metrics"},
|
||||
URLs: []string{s.URL},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package manager
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/didi/nightingale/src/models"
|
||||
"github.com/didi/nightingale/src/modules/monapi/plugins/prometheus"
|
||||
|
@ -14,20 +13,10 @@ import (
|
|||
)
|
||||
|
||||
func TestManager(t *testing.T) {
|
||||
{
|
||||
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, sampleTextFormat) })
|
||||
server := &http.Server{Addr: ":18080"}
|
||||
go func() {
|
||||
server.ListenAndServe()
|
||||
}()
|
||||
defer server.Shutdown(context.Background())
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, sampleTextFormat) }))
|
||||
defer s.Close()
|
||||
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
}
|
||||
|
||||
promRule := prometheus.PrometheusRule{
|
||||
URLs: []string{"http://localhost:18080/metrics"},
|
||||
}
|
||||
promRule := prometheus.PrometheusRule{URLs: []string{s.URL}}
|
||||
|
||||
b, err := json.Marshal(promRule)
|
||||
if err != nil {
|
||||
|
|
|
@ -508,7 +508,7 @@ func rstPassword(c *gin.Context) {
|
|||
return _e("Cannot find the user by %s", in.Arg)
|
||||
}
|
||||
|
||||
lc, err := models.LoginCodeGet("code=? and login_type=?", in.Code, models.LOGIN_T_RST)
|
||||
lc, err := models.LoginCodeGet("username=? and code=? and login_type=?", user.Username, in.Code, models.LOGIN_T_RST)
|
||||
if err != nil {
|
||||
return _e("Invalid code")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue