feat(go): advance validation sidecar toward production
This commit is contained in:
parent
6a06eba255
commit
f85c2e831a
92 changed files with 8881 additions and 91 deletions
48
go-agent/internal/sdnotify/notify_test.go
Normal file
48
go-agent/internal/sdnotify/notify_test.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package sdnotify
|
||||
|
||||
import (
|
||||
"net"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDisabledNotifierIsNoOp(t *testing.T) {
|
||||
if err := New("").Notify("READY=1"); err != nil {
|
||||
t.Fatalf("disabled notifier: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifierSendsDatagram(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "notify.sock")
|
||||
listener, err := net.ListenUnixgram("unixgram", &net.UnixAddr{Name: path, Net: "unixgram"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer listener.Close()
|
||||
if err := New(path).Notify("READY=1\nSTATUS=initialized"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := listener.SetReadDeadline(time.Now().Add(time.Second)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buffer := make([]byte, 128)
|
||||
read, _, err := listener.ReadFromUnix(buffer)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := string(buffer[:read]); got != "READY=1\nSTATUS=initialized" {
|
||||
t.Fatalf("notification=%q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifierRejectsInvalidState(t *testing.T) {
|
||||
if err := New("unused").Notify(""); err == nil {
|
||||
t.Fatal("empty state accepted")
|
||||
}
|
||||
if err := New("unused").Notify("READY=1\x00STATUS=bad"); err == nil {
|
||||
t.Fatal("NUL state accepted")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue