Skip to content

Commit

Permalink
Add e2e smoke test for FIFO mode
Browse files Browse the repository at this point in the history
  • Loading branch information
glrf committed Nov 21, 2022
1 parent 9b97ac8 commit 1386331
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"path/filepath"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -65,6 +66,24 @@ func TestE2E_MasterThenFault(t *testing.T) {
assert.NoErrorf(t, done(), "failed to stop master command")
}

func TestE2E_FIFO(t *testing.T) {
conf, cleanup, err := setupConfig(t.Name(), "192.168.1.1/32")
require.NoErrorf(t, err, "failed to setup test env")
defer cleanup()
pname, pipe, removePipe, err := setupFifo(t.Name())
require.NoErrorf(t, err, "failed to setup pipe")
defer removePipe()

cmd := exec.Command("./floaty", "--fifo", conf, pname)
out, stop, err := startCmd(cmd)
require.NoError(t, err)
defer stop()

_, err = pipe.Write([]byte(fmt.Sprintf("INSTANCE %q MASTER 100\n", t.Name())))
require.NoError(t, err)
expectUpdate(t, out, "192.168.1.1/32", 3)
}

func startCmd(cmd *exec.Cmd) (*bytes.Buffer, func() error, error) {
out := &bytes.Buffer{}
cmd.Stdout = out
Expand Down Expand Up @@ -165,3 +184,24 @@ vrrp_instance %s {
}
return confF, cleanup, nil
}

func setupFifo(name string) (string, io.Writer, func() error, error) {
dir, err := os.MkdirTemp("", name)
if err != nil {
return "", nil, nil, err
}
cleanup := func() error {
return os.RemoveAll(dir)
}
pname := filepath.Join(dir, "pipe")
err = syscall.Mkfifo(pname, 0666)
if err != nil {
return "", nil, cleanup, err
}

f, err := os.OpenFile(pname, os.O_RDWR|os.O_CREATE|os.O_APPEND|syscall.O_NONBLOCK, 0777)
if err != nil {
return "", nil, cleanup, err
}
return pname, f, cleanup, nil
}

0 comments on commit 1386331

Please sign in to comment.