Migrate tests from "store/storetest/command_webhook_store.go" to use testify (#12773)
* Migrate tests to use testify * Remove dangling semicolon * Fix failing test * Change from assert to require.Nil
Этот коммит содержится в:
коммит произвёл
Saturnino Abril
родитель
4f7bd2200d
Коммит
94db07f65f
@@ -4,14 +4,13 @@
|
|||||||
package storetest
|
package storetest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/store"
|
"github.com/mattermost/mattermost-server/store"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCommandWebhookStore(t *testing.T, ss store.Store) {
|
func TestCommandWebhookStore(t *testing.T, ss store.Store) {
|
||||||
@@ -29,17 +28,12 @@ func testCommandWebhookStore(t *testing.T, ss store.Store) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
var r1 *model.CommandWebhook
|
var r1 *model.CommandWebhook
|
||||||
if r1, err = cws.Get(h1.Id); err != nil {
|
r1, err = cws.Get(h1.Id)
|
||||||
t.Fatal(err)
|
require.Nil(t, err)
|
||||||
} else {
|
assert.Equal(t, *r1, *h1, "invalid returned webhook")
|
||||||
if *r1 != *h1 {
|
|
||||||
t.Fatal("invalid returned webhook")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = cws.Get("123"); err.StatusCode != http.StatusNotFound {
|
_, err = cws.Get("123")
|
||||||
t.Fatal("Should have set the status as not found for missing id")
|
assert.Equal(t, err.StatusCode, http.StatusNotFound, "Should have set the status as not found for missing id")
|
||||||
}
|
|
||||||
|
|
||||||
h2 := &model.CommandWebhook{}
|
h2 := &model.CommandWebhook{}
|
||||||
h2.CreateAt = model.GetMillis() - 2*model.COMMAND_WEBHOOK_LIFETIME
|
h2.CreateAt = model.GetMillis() - 2*model.COMMAND_WEBHOOK_LIFETIME
|
||||||
@@ -49,25 +43,22 @@ func testCommandWebhookStore(t *testing.T, ss store.Store) {
|
|||||||
h2, err = cws.Save(h2)
|
h2, err = cws.Save(h2)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if _, err := cws.Get(h2.Id); err == nil || err.StatusCode != http.StatusNotFound {
|
_, err = cws.Get(h2.Id)
|
||||||
t.Fatal("Should have set the status as not found for expired webhook")
|
require.NotNil(t, err, "Should have set the status as not found for expired webhook")
|
||||||
}
|
assert.Equal(t, err.StatusCode, http.StatusNotFound, "Should have set the status as not found for expired webhook")
|
||||||
|
|
||||||
cws.Cleanup()
|
cws.Cleanup()
|
||||||
|
|
||||||
if _, err := cws.Get(h1.Id); err != nil {
|
_, err = cws.Get(h1.Id)
|
||||||
t.Fatal("Should have no error getting unexpired webhook")
|
require.Nil(t, err, "Should have no error getting unexpired webhook")
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := cws.Get(h2.Id); err.StatusCode != http.StatusNotFound {
|
_, err = cws.Get(h2.Id)
|
||||||
t.Fatal("Should have set the status as not found for expired webhook")
|
assert.Equal(t, err.StatusCode, http.StatusNotFound, "Should have set the status as not found for expired webhook")
|
||||||
}
|
|
||||||
|
|
||||||
if err := cws.TryUse(h1.Id, 1); err != nil {
|
err = cws.TryUse(h1.Id, 1)
|
||||||
t.Fatal("Should be able to use webhook once")
|
require.Nil(t, err, "Should be able to use webhook once")
|
||||||
}
|
|
||||||
|
|
||||||
if err := cws.TryUse(h1.Id, 1); err == nil || err.StatusCode != http.StatusBadRequest {
|
err = cws.TryUse(h1.Id, 1)
|
||||||
t.Fatal("Should be able to use webhook once")
|
require.NotNil(t, err, "Should be able to use webhook once")
|
||||||
}
|
assert.Equal(t, err.StatusCode, http.StatusBadRequest, "Should be able to use webhook once")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user