2023-11-05 19:03:58 +01:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2023-12-10 20:21:54 +01:00
|
|
|
func getExampleConfiguration() *DaemonConfiguration {
|
|
|
|
return &DaemonConfiguration{
|
2023-11-05 19:03:58 +01:00
|
|
|
CertificatePath: "./cert/cert.pem",
|
|
|
|
PrivateKeyPath: "./cert/key.pem",
|
|
|
|
CaCertificatePath: "./cert/ca.pems",
|
|
|
|
SkipCertVerification: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigurationCertificatePathEmpty(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.CertificatePath = ""
|
|
|
|
|
2023-12-10 20:21:54 +01:00
|
|
|
err := ValidateDaemonConfiguration(conf)
|
2023-11-05 19:03:58 +01:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigurationPrivateKeyPathEmpty(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.PrivateKeyPath = ""
|
|
|
|
|
2023-12-10 20:21:54 +01:00
|
|
|
err := ValidateDaemonConfiguration(conf)
|
2023-11-05 19:03:58 +01:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigurationCaCertificatePathEmpty(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.CaCertificatePath = ""
|
|
|
|
|
2023-12-10 20:21:54 +01:00
|
|
|
err := ValidateDaemonConfiguration(conf)
|
2023-11-05 19:03:58 +01:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigurationGrpcPortEmpty(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
2023-12-10 20:21:54 +01:00
|
|
|
conf.GrpcPort = 0
|
2023-11-05 19:03:58 +01:00
|
|
|
|
2023-12-10 20:21:54 +01:00
|
|
|
err := ValidateDaemonConfiguration(conf)
|
2023-11-05 19:03:58 +01:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-10 20:21:54 +01:00
|
|
|
func TestValidConfiguration(t *testing.T) {
|
2023-11-05 19:03:58 +01:00
|
|
|
conf := getExampleConfiguration()
|
|
|
|
|
2023-12-10 20:21:54 +01:00
|
|
|
err := ValidateDaemonConfiguration(conf)
|
2023-11-05 19:03:58 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|