mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
96cbd10651
This fixes 9 places in the `server/service` tests where err variables were being dropped. No new test failures identified.
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/go-kit/kit/log"
|
|
"github.com/kolide/fleet/server/logging"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestRotateLoggerSIGHUP verifies that the osqueryd logfile is rotated by
|
|
// sending a SIGHUP signal.
|
|
func TestRotateLoggerSIGHUP(t *testing.T) {
|
|
ctx := context.Background()
|
|
filePrefix := "kolide-log-rotate-test"
|
|
f, err := ioutil.TempFile("/tmp", filePrefix)
|
|
require.Nil(t, err)
|
|
defer os.Remove(f.Name())
|
|
|
|
logFile, err := logging.NewFilesystemLogWriter(f.Name(), log.NewNopLogger(), true)
|
|
require.Nil(t, err)
|
|
|
|
// write a log line
|
|
logFile.Write(ctx, []json.RawMessage{json.RawMessage("msg1")})
|
|
|
|
sig := make(chan os.Signal, 1)
|
|
signal.Notify(sig, syscall.SIGHUP)
|
|
defer signal.Reset(syscall.SIGHUP)
|
|
|
|
// send SIGHUP to the process
|
|
err = syscall.Kill(syscall.Getpid(), syscall.SIGHUP)
|
|
require.Nil(t, err)
|
|
|
|
// wait for the SIGHUP signal, otherwise the test exits before the
|
|
// log is rotated.
|
|
<-sig
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
// write a new log line and verify that the original file includes
|
|
// the new log line but not any of the old ones.
|
|
logFile.Write(ctx, []json.RawMessage{json.RawMessage("msg2")})
|
|
logMsg, err := ioutil.ReadFile(f.Name())
|
|
require.Nil(t, err)
|
|
|
|
require.Equal(t, "msg2\n", string(logMsg))
|
|
}
|