LoraServer: make test fails on opening sql database

Compiling from source not using Docker; in loraserver:

make dev-requirements ran correctly
make requirements ran fine (after some work)
make test failed at:
0 0x0000000000d7652f in github.com/brocaar/loraserver/internal/test.(*DatabaseTestSuiteBase).SetupSuite
at /home/martin/Dropbox/go/src/github.com/brocaar/loraserver/internal/test/test.go:373
1 0x0000000000da2b01 in github.com/brocaar/loraserver/internal/api.(*NetworkServerAPITestSuite).SetupSuite
at ./network_server_new_test.go:31

db, err := common.OpenDatabase(conf.PostgresDSN)

conf.PostgresDSN is “postgres://localhost/loraserver_ns_test?sslmode=disable”

To my understanding this means open loraserver_ns_test database with user postgres, no password, and no sslmode.

I believe this was configured at line 63 of test/test.go

	c := &Config{
		RedisURL:    "redis://localhost:6379",
		PostgresDSN: "postgres://localhost/loraserver_ns_test?sslmode=disable",
	}

When I look at the err returned, I see:
Message: “password authentication failed for user "martin"”
Not sure why the user is martin and not postgres. Irrespective, I don’t have a loraserver_ns_test data base, and didn’t see docs to make one. Would I be better to add a new database or should I change test.go’s GetConfig() function to a database I have. I worry about having a database without a password; is this safe.

I do have a configuration file in: $HOME/.config/loraserver/loraserver.toml as documented in:

and it has a line:
dsn=“user=loraserver dbname=loraserver password=my_password sslmode=disable”
Shouldn’t this configuration file be used during testing?
After changing line 63 in test/test.go to:
PostgresDSN: “user=loraserver dbname=loraserver password=anlg4all sslmode=disable”,
the test passed for >go test in loraserver/internal/api

Summary: I think I understand the error, but I don’t understand how best to do configuration to be used during >make test for loraserver (and for the other programs). Can we set up the configuration environment so it is used by all of the >make test programs? Thank you for your help.

I recommend to use the Docker Compose environment as it should work out-of-the-box :slight_smile: I do have control over how the Docker Environment is setup, but I don’t have control in how you setup your local environment and depending your distribution you might end up using outdated tools like the Go compiler etc…

If you proceed to test without, please note that the GetConfig function contains lines where it overwrites the RedisURL and PostgresDSN from environment variables, when these are set.

Brocaar, thank you for getting back to me. I’m a newbi with Docker Compose; have you set it so delve can be used to debug changes for a custom App Server?

No, but feel free to propose modifications if you think this would be useful to integrate this into the Compose environment.