Esempio n. 1
0
func TestNewWatcher_renewVault(t *testing.T) {
	clients := dep.NewClientSet()

	w, err := NewWatcher(&WatcherConfig{
		Clients:    clients,
		Once:       true,
		RenewVault: true,
	})
	if err != nil {
		t.Fatal(err)
	}
	defer w.Stop()

	if !w.Watching(new(dep.VaultToken)) {
		t.Errorf("expected watcher to be renewing vault token")
	}
}
Esempio n. 2
0
func TestNewWatcher_values(t *testing.T) {
	clients := dep.NewClientSet()

	w, err := NewWatcher(&WatcherConfig{
		Clients: clients,
		Once:    true,
	})
	if err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(w.config.Clients, clients) {
		t.Errorf("expected %#v to be %#v", w.config.Clients, clients)
	}

	if w.config.Once != true {
		t.Errorf("expected w.config.Once to be true")
	}
}
Esempio n. 3
0
// newClientSet creates a new client set from the given config.
func newClientSet(config *Config) (*dep.ClientSet, error) {
	clients := dep.NewClientSet()

	consul, err := newConsulClient(config)
	if err != nil {
		return nil, err
	}
	if err := clients.Add(consul); err != nil {
		return nil, err
	}

	vault, err := newVaultClient(config)
	if err != nil {
		return nil, err
	}
	if err := clients.Add(vault); err != nil {
		return nil, err
	}

	return clients, nil
}
Esempio n. 4
0
package watch

import (
	"fmt"
	"reflect"
	"strings"
	"testing"
	"time"

	dep "github.com/teemupo/consul-template/dependency"
)

var defaultWatcherConfig = &WatcherConfig{
	Clients:   dep.NewClientSet(),
	Once:      true,
	RetryFunc: func(time.Duration) time.Duration { return 0 },
}

func TestNewWatcher_noConfig(t *testing.T) {
	_, err := NewWatcher(nil)
	if err == nil {
		t.Fatal("expected error, but nothing was returned")
	}

	expected := "watcher: missing config"
	if !strings.Contains(err.Error(), expected) {
		t.Errorf("expected %q to contain %q", err.Error(), expected)
	}
}

func TestNewWatcher_defaultValues(t *testing.T) {