mirror of
https://github.com/dnote/dnote
synced 2026-03-15 15:05:51 +01:00
* Require explicit configuration for database connection * Test validation * Remove stutter * Only use packr for self hosting * Restart server upon change
79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package database
|
|
|
|
import (
|
|
"github.com/dnote/dnote/pkg/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateConfig(t *testing.T) {
|
|
testCases := []struct {
|
|
input Config
|
|
expected error
|
|
}{
|
|
{
|
|
input: Config{
|
|
Host: "mockHost",
|
|
Port: "mockPort",
|
|
Name: "mockName",
|
|
User: "mockUser",
|
|
Password: "mockPassword",
|
|
},
|
|
expected: nil,
|
|
},
|
|
{
|
|
input: Config{
|
|
Host: "mockHost",
|
|
Port: "mockPort",
|
|
Name: "mockName",
|
|
User: "mockUser",
|
|
},
|
|
expected: nil,
|
|
},
|
|
{
|
|
input: Config{
|
|
Port: "mockPort",
|
|
Name: "mockName",
|
|
User: "mockUser",
|
|
Password: "mockPassword",
|
|
},
|
|
expected: ErrConfigMissingHost,
|
|
},
|
|
{
|
|
input: Config{
|
|
Host: "mockHost",
|
|
Name: "mockName",
|
|
User: "mockUser",
|
|
Password: "mockPassword",
|
|
},
|
|
expected: ErrConfigMissingPort,
|
|
},
|
|
{
|
|
input: Config{
|
|
Host: "mockHost",
|
|
Port: "mockPort",
|
|
User: "mockUser",
|
|
Password: "mockPassword",
|
|
},
|
|
expected: ErrConfigMissingName,
|
|
},
|
|
{
|
|
input: Config{
|
|
Host: "mockHost",
|
|
Port: "mockPort",
|
|
Name: "mockName",
|
|
Password: "mockPassword",
|
|
},
|
|
expected: ErrConfigMissingUser,
|
|
},
|
|
{
|
|
input: Config{},
|
|
expected: ErrConfigMissingHost,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
result := validateConfig(tc.input)
|
|
|
|
assert.Equal(t, result, tc.expected, "result mismatch")
|
|
}
|
|
}
|