Skip to content

Commit

Permalink
Disable logs in tests by default
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed May 11, 2020
1 parent 6679967 commit 1e3e069
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package config

// FAST_POLL used for fast testing
var FAST_POLL = false
23 changes: 23 additions & 0 deletions internal/testutils/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package testutils

import (
"io/ioutil"
"os"

"log"

"github.com/sirupsen/logrus"
"sigs.k8s.io/external-dns/internal/config"
)

func init() {
config.FAST_POLL = true
if os.Getenv("DEBUG") == "" {
logrus.SetOutput(ioutil.Discard)
log.SetOutput(ioutil.Discard)
} else {
if level, err := logrus.ParseLevel(os.Getenv("DEBUG")); err == nil {
logrus.SetLevel(level)
}
}
}
8 changes: 3 additions & 5 deletions source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/internal/config"
)

const (
Expand Down Expand Up @@ -226,13 +227,10 @@ func matchLabelSelector(selector labels.Selector, srcAnnotations map[string]stri
return selector.Matches(annotations)
}

// FAST_POLL used for fast testing
var FAST_POLL = false

func poll(interval time.Duration, timeout time.Duration, condition wait.ConditionFunc) error {
if FAST_POLL {
if config.FAST_POLL {
interval = 10 * time.Millisecond
timeout = 10 * time.Second
timeout = 5 * time.Second
}

return wait.Poll(interval, timeout, condition)
Expand Down
7 changes: 0 additions & 7 deletions source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package source
import (
"context"
"fmt"
"os"
"testing"
"time"

Expand All @@ -29,12 +28,6 @@ import (
"sigs.k8s.io/external-dns/internal/testutils"
)

func TestMain(m *testing.M) {
FAST_POLL = true
// call flag.Parse() here if TestMain uses flags
os.Exit(m.Run())
}

func TestGetTTLFromAnnotations(t *testing.T) {
for _, tc := range []struct {
title string
Expand Down

0 comments on commit 1e3e069

Please sign in to comment.