appveyor: Run logmon tests
This commit is contained in:
parent
634ada671e
commit
e1151f743b
|
@ -46,6 +46,7 @@ test_script:
|
|||
gotestsum --junitfile results.xml
|
||||
github.com/hashicorp/nomad/drivers/docker
|
||||
github.com/hashicorp/nomad/client/lib/fifo
|
||||
github.com/hashicorp/nomad/client/logmon
|
||||
# on_finish:
|
||||
# - ps: |
|
||||
# Push-AppveyorArtifact (Resolve-Path .\results.xml)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package fifo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
|
@ -75,7 +76,7 @@ func CreateAndRead(path string) (func() (io.ReadCloser, error), error) {
|
|||
OutputBufferSize: PipeBufferSize,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to create fifo: %v", err)
|
||||
}
|
||||
|
||||
return func() (io.ReadCloser, error) {
|
||||
|
@ -88,7 +89,7 @@ func CreateAndRead(path string) (func() (io.ReadCloser, error), error) {
|
|||
func OpenReader(path string) (io.ReadCloser, error) {
|
||||
l, err := winio.ListenOnlyPipe(path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to open fifo listener: %v", err)
|
||||
}
|
||||
|
||||
return &winFIFO{listener: l}, nil
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/client/lib/fifo"
|
||||
|
@ -16,13 +17,23 @@ import (
|
|||
|
||||
func TestLogmon_Start_rotate(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
stdoutLog := "stdout"
|
||||
stderrLog := "stderr"
|
||||
|
||||
var stdoutFifoPath, stderrFifoPath string
|
||||
|
||||
dir, err := ioutil.TempDir("", "nomadtest")
|
||||
require.NoError(err)
|
||||
defer os.RemoveAll(dir)
|
||||
stdoutLog := "stdout"
|
||||
stdoutFifoPath := filepath.Join(dir, "stdout.fifo")
|
||||
stderrLog := "stderr"
|
||||
stderrFifoPath := filepath.Join(dir, "stderr.fifo")
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
stdoutFifoPath = "//./pipe/test-rotate.stdout"
|
||||
stderrFifoPath = "//./pipe/test-rotate.stderr"
|
||||
} else {
|
||||
stdoutFifoPath = filepath.Join(dir, "stdout.fifo")
|
||||
stderrFifoPath = filepath.Join(dir, "stderr.fifo")
|
||||
}
|
||||
|
||||
cfg := &LogConfig{
|
||||
LogDir: dir,
|
||||
|
@ -69,13 +80,23 @@ func TestLogmon_Start_rotate(t *testing.T) {
|
|||
// asserts that calling Start twice restarts the log rotator
|
||||
func TestLogmon_Start_restart(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
stdoutLog := "stdout"
|
||||
stderrLog := "stderr"
|
||||
|
||||
var stdoutFifoPath, stderrFifoPath string
|
||||
|
||||
dir, err := ioutil.TempDir("", "nomadtest")
|
||||
require.NoError(err)
|
||||
defer os.RemoveAll(dir)
|
||||
stdoutLog := "stdout"
|
||||
stdoutFifoPath := filepath.Join(dir, "stdout.fifo")
|
||||
stderrLog := "stderr"
|
||||
stderrFifoPath := filepath.Join(dir, "stderr.fifo")
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
stdoutFifoPath = "//./pipe/test-restart.stdout"
|
||||
stderrFifoPath = "//./pipe/test-restart.stderr"
|
||||
} else {
|
||||
stdoutFifoPath = filepath.Join(dir, "stdout.fifo")
|
||||
stderrFifoPath = filepath.Join(dir, "stderr.fifo")
|
||||
}
|
||||
|
||||
cfg := &LogConfig{
|
||||
LogDir: dir,
|
||||
|
@ -122,6 +143,11 @@ func TestLogmon_Start_restart(t *testing.T) {
|
|||
require.NoError(err)
|
||||
})
|
||||
|
||||
require.NoError(lm.Stop())
|
||||
|
||||
// Start logmon again and assert that it appended to the file
|
||||
require.NoError(lm.Start(cfg))
|
||||
|
||||
stdout, err = fifo.OpenWriter(stdoutFifoPath)
|
||||
require.NoError(err)
|
||||
stderr, err = fifo.OpenWriter(stderrFifoPath)
|
||||
|
@ -140,14 +166,6 @@ func TestLogmon_Start_restart(t *testing.T) {
|
|||
require.NoError(err)
|
||||
})
|
||||
|
||||
// Start logmon again and assert that it appended to the file
|
||||
require.NoError(lm.Start(cfg))
|
||||
|
||||
stdout, err = fifo.OpenWriter(stdoutFifoPath)
|
||||
require.NoError(err)
|
||||
stderr, err = fifo.OpenWriter(stderrFifoPath)
|
||||
require.NoError(err)
|
||||
|
||||
_, err = stdout.Write([]byte("st\n"))
|
||||
require.NoError(err)
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
|
|
Loading…
Reference in New Issue