You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5 KiB

package mock
import (
"context"
"tera-clone/services/tera-api/internal/networkconfig"
"testing"
"time"
)
func TestStartupPoliciesRejectMissingEnabledCredentials(t *testing.T) {
s := NewStore(time.Now)
defer s.Close()
if err := s.VerifyStartupPolicies(context.Background()); err != nil {
t.Fatal(err)
}
s.runningEmail.Enabled = true
s.runningEmail.AuthEnabled = true
s.runningEmail.SMTPHost = "smtp.example"
s.runningEmail.SMTPPort = 587
s.runningEmail.Username = "test"
s.runningEmail.From = "from@example.com"
s.runningEmail.To = []string{"to@example.com"}
if err := s.VerifyStartupPolicies(context.Background()); err == nil {
t.Fatal("missing SMTP secret accepted")
}
}
func TestStartupNetworkRequiresAppliedAddressEvenWhenLinkIsDown(t *testing.T) {
wanted := networkconfig.Config{Advanced: networkconfig.AdvancedConfig{Mode: "single"}, Interfaces: []networkconfig.Interface{{Name: "Interface-1", Device: "eth0", AddressMode: "static", Address: "192.168.0.223/24"}}}
status := networkconfig.Status{Interfaces: []networkconfig.ActualInterface{{Device: "eth0", Link: "down", Addresses: []string{"192.168.0.223/24"}}}}
if err := verifyStartupNetworkInterfaces(wanted, status); err != nil {
t.Fatal(err)
}
status.Interfaces[0].Addresses = nil
if err := verifyStartupNetworkInterfaces(wanted, status); err == nil {
t.Fatal("missing IP accepted")
}
status.Interfaces = nil
if err := verifyStartupNetworkInterfaces(wanted, status); err == nil {
t.Fatal("missing interface accepted")
}
}