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.
39 lines
1.2 KiB
39 lines
1.2 KiB
package netsocket
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"tera-clone/services/tera-api/internal/networkconfig"
|
|
)
|
|
|
|
func TestClientServerApplyConfirmRoundTrip(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "control.sock")
|
|
listener, err := net.Listen("unix", path)
|
|
if err != nil {
|
|
t.Skipf("Unix sockets unavailable: %v", err)
|
|
}
|
|
defer listener.Close()
|
|
controller := &networkconfig.MockController{}
|
|
server := Server{Controller: controller}
|
|
done := make(chan error, 1)
|
|
go func() { done <- server.Serve(listener) }()
|
|
|
|
client := NewClient(path)
|
|
config := networkconfig.Config{Interfaces: []networkconfig.Interface{
|
|
{Name: "Interface-1", Device: "eth0", Role: "internal", Address: "192.168.0.223/24", Weight: 1},
|
|
{Name: "Interface-2", Device: "eth1", Role: "external", Address: "192.168.78.55/24", Gateway: "192.168.78.1", Weight: 1},
|
|
}}
|
|
result, err := client.Apply(context.Background(), config)
|
|
if err != nil || result.TransactionID == "" {
|
|
t.Fatalf("Apply() = %+v, %v", result, err)
|
|
}
|
|
status, err := client.Confirm(context.Background(), result.TransactionID)
|
|
if err != nil || status.State != "idle" {
|
|
t.Fatalf("Confirm() = %+v, %v", status, err)
|
|
}
|
|
_ = listener.Close()
|
|
<-done
|
|
}
|
|
|