Skip to content

Commit

Permalink
Prevent glog from writing to /tmp during tests
Browse files Browse the repository at this point in the history
glog (brought by client-go dep) registers an init() that configure the
default logger to write logs as files in /tmp. This is disabled by
sp13/pflags, which is loaded by default in Katafygio, but not during
tests.

So forcing glog to use stderr instead of files prevent a few files
from "leaking" in /tmp every time we run unit tests.
  • Loading branch information
bpineau committed Apr 19, 2018
1 parent 4afbd65 commit b0949cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ func init() {
log.Fatal("Failed to bind cli argument:", err)
}

RootCmd.PersistentFlags().BoolVarP(&dryRun, "dry-run", "d", false, "Dry-run mode: don't store anything.")
RootCmd.PersistentFlags().BoolVarP(&dryRun, "dry-run", "d", false, "Dry-run mode: don't store anything")
bindPFlag("dry-run", "dry-run")

RootCmd.PersistentFlags().BoolVarP(&dumpMode, "dump-only", "m", false, "Dump mode: dump everything and exit")
RootCmd.PersistentFlags().BoolVarP(&dumpMode, "dump-only", "m", false, "Dump mode: dump everything once and exit")
bindPFlag("dump-only", "dump-only")

RootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "v", "info", "Log level")
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller

import (
"flag"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -73,6 +74,7 @@ var (
)

func TestController(t *testing.T) {
flag.Lookup("logtostderr").Value.Set("true")

conf := &config.KfConfig{
Logger: log.New("info", "", "test"),
Expand Down

0 comments on commit b0949cb

Please sign in to comment.