grafana/pkg/middleware/logger_test.go
idafurjes 6c5a573772
Chore: Move ReqContext to contexthandler service (#62102)
* Chore: Move ReqContext to contexthandler service

* Rename package to contextmodel

* Generate ngalert files

* Remove unused imports
2023-01-27 08:50:36 +01:00

58 lines
1.2 KiB
Go

package middleware
import (
"testing"
"github.com/grafana/grafana/pkg/infra/log"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/stretchr/testify/assert"
)
func Test_sanitizeURL(t *testing.T) {
type args struct {
ctx *contextmodel.ReqContext
s string
}
tests := []struct {
name string
args args
want string
}{
{
name: "Receiving empty string should return it",
args: args{
ctx: &contextmodel.ReqContext{
Logger: log.New("test.logger"),
},
s: "",
},
want: "",
},
{
name: "Receiving valid URL string should return it parsed",
args: args{
ctx: &contextmodel.ReqContext{
Logger: log.New("test.logger"),
},
s: "https://grafana.com/",
},
want: "https://grafana.com/",
},
{
name: "Receiving invalid URL string should return empty string",
args: args{
ctx: &contextmodel.ReqContext{
Logger: log.New("test.logger"),
},
s: "this is not a valid URL",
},
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, SanitizeURL(tt.args.ctx, tt.args.s), "sanitizeURL(%v, %v)", tt.args.ctx, tt.args.s)
})
}
}