smegmesh/pkg/conf/conf_test.go

67 lines
1.3 KiB
Go
Raw Normal View History

2023-11-05 19:03:58 +01:00
package conf
import "testing"
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 = ""
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 = ""
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 = ""
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()
conf.GrpcPort = 0
2023-11-05 19:03:58 +01:00
err := ValidateDaemonConfiguration(conf)
2023-11-05 19:03:58 +01:00
if err == nil {
t.Fatal(`error should be thrown`)
}
}
func TestValidConfiguration(t *testing.T) {
2023-11-05 19:03:58 +01:00
conf := getExampleConfiguration()
err := ValidateDaemonConfiguration(conf)
2023-11-05 19:03:58 +01:00
if err != nil {
t.Error(err)
}
}