Passing t to all tests setup functions (#13841)
* Passing t to all tests setup functions * Fixing build
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3b732fe257
Коммит
1d1ab03c38
@@ -19,7 +19,7 @@ func handlerForHTTPErrors(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func TestHandlerServeHTTPErrors(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
web := New(th.Server, th.Server.AppOptions, th.Server.Router)
|
||||
@@ -59,7 +59,7 @@ func handlerForHTTPSecureTransport(c *Context, w http.ResponseWriter, r *http.Re
|
||||
}
|
||||
|
||||
func TestHandlerServeHTTPSecureTransport(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(config *model.Config) {
|
||||
@@ -103,7 +103,7 @@ func handlerForCSRFToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func TestHandlerServeCSRFToken(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
session := &model.Session{
|
||||
@@ -243,7 +243,7 @@ func handlerForCSPHeader(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func TestHandlerServeCSPHeader(t *testing.T) {
|
||||
t.Run("non-static", func(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
web := New(th.Server, th.Server.AppOptions, th.Server.Router)
|
||||
@@ -265,7 +265,7 @@ func TestHandlerServeCSPHeader(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("static, without subpath", func(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
web := New(th.Server, th.Server.AppOptions, th.Server.Router)
|
||||
@@ -287,7 +287,7 @@ func TestHandlerServeCSPHeader(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("static, with subpath", func(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
@@ -342,7 +342,7 @@ func TestHandlerServeInvalidToken(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Description, func(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
@@ -379,7 +379,7 @@ func TestHandlerServeInvalidToken(t *testing.T) {
|
||||
|
||||
func TestCheckCSRFToken(t *testing.T) {
|
||||
t.Run("should allow a POST request with a valid CSRF token header", func(t *testing.T) {
|
||||
th := Setup()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
h := &Handler{
|
||||
@@ -409,7 +409,7 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should allow a POST request with an X-Requested-With header", func(t *testing.T) {
|
||||
th := Setup()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
h := &Handler{
|
||||
@@ -440,7 +440,7 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should not allow a POST request with an X-Requested-With header with strict CSRF enforcement enabled", func(t *testing.T) {
|
||||
th := Setup()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
@@ -475,7 +475,7 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should not allow a POST request without either header", func(t *testing.T) {
|
||||
th := Setup()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
h := &Handler{
|
||||
@@ -504,7 +504,7 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should not check GET requests", func(t *testing.T) {
|
||||
th := Setup()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
h := &Handler{
|
||||
@@ -533,7 +533,7 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should not check a request passing the auth token in a header", func(t *testing.T) {
|
||||
th := Setup()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
h := &Handler{
|
||||
@@ -562,7 +562,7 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should not check a request passing a nil session", func(t *testing.T) {
|
||||
th := Setup()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
h := &Handler{
|
||||
@@ -587,7 +587,7 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should check requests for handlers that don't require a session but have one", func(t *testing.T) {
|
||||
th := Setup()
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
h := &Handler{
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func TestOAuthComplete_AccessDenied(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
c := &Context{
|
||||
@@ -45,7 +45,7 @@ func TestOAuthComplete_AccessDenied(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthorizeOAuthApp(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t).InitBasic()
|
||||
th.Login(ApiClient, th.SystemAdminUser)
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -130,7 +130,7 @@ func TestAuthorizeOAuthApp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeauthorizeOAuthApp(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t).InitBasic()
|
||||
th.Login(ApiClient, th.SystemAdminUser)
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -183,7 +183,7 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t).InitBasic()
|
||||
th.Login(ApiClient, th.SystemAdminUser)
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -356,7 +356,7 @@ func TestOAuthComplete(t *testing.T) {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t).InitBasic()
|
||||
th.Login(ApiClient, th.SystemAdminUser)
|
||||
defer th.TearDown()
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ type TestHelper struct {
|
||||
tempWorkspace string
|
||||
}
|
||||
|
||||
func Setup() *TestHelper {
|
||||
func Setup(tb testing.TB) *TestHelper {
|
||||
store := mainHelper.GetStore()
|
||||
store.DropAllTables()
|
||||
|
||||
@@ -130,7 +130,7 @@ func (th *TestHelper) TearDown() {
|
||||
}
|
||||
|
||||
func TestStaticFilesRequest(t *testing.T) {
|
||||
th := Setup().InitPlugins()
|
||||
th := Setup(t).InitPlugins()
|
||||
defer th.TearDown()
|
||||
|
||||
pluginID := "com.mattermost.sample"
|
||||
@@ -216,7 +216,7 @@ func TestStaticFilesRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPublicFilesRequest(t *testing.T) {
|
||||
th := Setup().InitPlugins()
|
||||
th := Setup(t).InitPlugins()
|
||||
defer th.TearDown()
|
||||
|
||||
pluginDir, err := ioutil.TempDir("", "")
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func TestIncomingWebhook(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
if !*th.App.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
@@ -232,7 +232,7 @@ func TestIncomingWebhook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCommandWebhooks(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
cmd, appErr := th.App.CreateCommand(&model.Command{
|
||||
|
||||
Ссылка в новой задаче
Block a user