use testhttp instead of http for ut ()

* use testhttp instead of http for ut
* bugfix: add username check
This commit is contained in:
yubo 2021-02-22 11:25:02 +08:00 committed by GitHub
parent 417a13c1be
commit 322cbf27dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 27 deletions
src/modules
monapi/plugins/prometheus
prober/manager
rdb/http

View File

@ -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},
})
}

View File

@ -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 {

View File

@ -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")
}