2023-11-05 19:03:58 +01:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func getExampleConfiguration() *WgMeshConfiguration {
|
|
|
|
return &WgMeshConfiguration{
|
|
|
|
CertificatePath: "./cert/cert.pem",
|
|
|
|
PrivateKeyPath: "./cert/key.pem",
|
|
|
|
CaCertificatePath: "./cert/ca.pems",
|
|
|
|
SkipCertVerification: true,
|
|
|
|
GrpcPort: "8080",
|
|
|
|
AdvertiseRoutes: true,
|
|
|
|
Endpoint: "localhost",
|
|
|
|
ClusterSize: 1,
|
|
|
|
SyncRate: 1,
|
|
|
|
InterClusterChance: 0.1,
|
|
|
|
BranchRate: 2,
|
2023-11-06 14:37:28 +01:00
|
|
|
KeepAliveTime: 4,
|
2023-11-05 19:03:58 +01:00
|
|
|
InfectionCount: 1,
|
2023-11-06 14:37:28 +01:00
|
|
|
Timeout: 2,
|
|
|
|
PruneTime: 20,
|
2023-11-05 19:03:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigurationCertificatePathEmpty(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.CertificatePath = ""
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigurationPrivateKeyPathEmpty(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.PrivateKeyPath = ""
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigurationCaCertificatePathEmpty(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.CaCertificatePath = ""
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigurationGrpcPortEmpty(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.GrpcPort = ""
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClusterSizeZero(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.ClusterSize = 0
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func SyncRateZero(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.SyncRate = 0
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BranchRateZero(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.BranchRate = 0
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func InfectionCountZero(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.InfectionCount = 0
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func KeepAliveRateZero(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
2023-11-06 10:54:06 +01:00
|
|
|
conf.KeepAliveTime = 0
|
2023-11-05 19:03:58 +01:00
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidCOnfiguration(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2023-11-06 14:37:28 +01:00
|
|
|
|
|
|
|
func TestTimeout(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.Timeout = 0
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPruneTimeZero(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.PruneTime = 0
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf(`Error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPruneTimeLessThanKeepAliveTime(t *testing.T) {
|
|
|
|
conf := getExampleConfiguration()
|
|
|
|
conf.PruneTime = 1
|
|
|
|
|
|
|
|
err := ValidateConfiguration(conf)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf(`Error should be thrown`)
|
|
|
|
}
|
|
|
|
}
|