diff --git a/README.md b/README.md index c4cd54c..aeea4e1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/internal/api/application_test.go b/internal/api/application_test.go index 0306cb2..ad2ba69 100644 --- a/internal/api/application_test.go +++ b/internal/api/application_test.go @@ -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, diff --git a/tests/mockups/dispatcher.go b/tests/mockups/dispatcher.go index b273d39..b0accab 100644 --- a/tests/mockups/dispatcher.go +++ b/tests/mockups/dispatcher.go @@ -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 }