get rid of external data for testing

This commit is contained in:
Cubicroot 2021-06-28 18:56:24 +02:00
parent 4c84589172
commit 3ad8a5044e
3 changed files with 25 additions and 17 deletions

View file

@ -174,8 +174,6 @@ git clone https://github.com/pushbits/server.git
Testing is essential for deliviering a good and reliable software. PushBits uses golangs integrated test features. Unfortunately writing tests is quite time consuming and therefore not every feature and every line of code is automatically tested. Feel free to help us improve our tests.
Some tests depend on confidential configuration data. Therefore provide a `config.yml` in PushBits main folder.
To run tests for a single (sub)module you can simply execute the following command in the modules folder.
```bash

View file

@ -26,15 +26,15 @@ var SuccessAplications map[uint][]model.Application
func TestMain(m *testing.M) {
// Get main config and adapt
config, err := mockups.ReadConfig("../../config.yml", true)
if err != nil {
cleanUp()
log.Println("Can not read config: ", err)
os.Exit(1)
}
config := &configuration.Configuration{}
config.Database.Connection = "pushbits-test.db"
config.Database.Dialect = "sqlite3"
config.Crypto.Argon2.Iterations = 4
config.Crypto.Argon2.Parallelism = 4
config.Crypto.Argon2.Memory = 131072
config.Crypto.Argon2.SaltLength = 16
config.Crypto.Argon2.KeyLength = 32
// Set up test environment
db, err := mockups.GetEmptyDatabase(config.Crypto)
@ -312,10 +312,8 @@ func TestApi_DeleteApplication(t *testing.T) {
// GetApplicationHandler creates and returns an application handler
func getApplicationHandler(c *configuration.Configuration) (*ApplicationHandler, error) {
dispatcher, err := mockups.GetMatrixDispatcher(c.Matrix.Homeserver, c.Matrix.Username, c.Matrix.Password, c.Crypto)
if err != nil {
return nil, err
}
dispatcher := &mockups.MockDispatcher{}
return &ApplicationHandler{
DB: TestDatabase,
DP: dispatcher,

View file

@ -1,11 +1,23 @@
package mockups
import (
"github.com/pushbits/server/internal/configuration"
"github.com/pushbits/server/internal/dispatcher"
"fmt"
"github.com/pushbits/server/internal/model"
)
// GetMatrixDispatcher creates and returns a matrix dispatcher
func GetMatrixDispatcher(homeserver, username, password string, confCrypto configuration.CryptoConfig) (*dispatcher.Dispatcher, error) {
return dispatcher.Create(homeserver, username, password, configuration.Formatting{})
// MockDispatcher is a dispatcher used for testing - it does not need any storage interface
type MockDispatcher struct {
}
func (d *MockDispatcher) RegisterApplication(id uint, name, token, user string) (string, error) {
return fmt.Sprintf("%d-%s", id, name), nil
}
func (d *MockDispatcher) DeregisterApplication(a *model.Application, u *model.User) error {
return nil
}
func (d *MockDispatcher) UpdateApplication(a *model.Application) error {
return nil
}