コード例 #1
0
ファイル: config_test.go プロジェクト: achilleasa/usrv
func TestEventStreamCancellationAfterDebouncing(t *testing.T) {
	origDebounceTime := cfgDebounceTime
	cfgDebounceTime = 1 * time.Millisecond
	defer func() {
		cfgDebounceTime = origDebounceTime
	}()

	expCfg := map[string]string{
		"key1": "value1",
		"key2": "value2",
	}

	defaults.Set("foo", expCfg)
	cfgChan, unsubChan := EventStream("foo")
	<-time.After(100 * time.Millisecond)
	close(unsubChan)
	<-time.After(100 * time.Millisecond)

	select {
	case <-cfgChan:
		t.Fatal("received config after cancelling subscription")
	case <-time.After(1 * time.Second):
		break
	}
}
コード例 #2
0
ファイル: flag_test.go プロジェクト: achilleasa/usrv
func TestFlagCancelDynamicUpdates(t *testing.T) {
	defaults.Set("generic-flag-1", map[string]string{"_": "hello"})

	f := &flagImpl{}
	f.init(stringMapper, []string{"generic-flag-1"})
	f.CancelDynamicUpdates()

	// Calling cancel a second time should be a no-op
	f.CancelDynamicUpdates()

	expValue := "test"
	f.set(expValue)

	select {
	case <-f.ChangeChan():
	case <-time.After(1 * time.Second):
		t.Fatal("timeout waiting for change evnet")
	}

	value := f.get().(string)

	if value != expValue {
		t.Fatalf("expected value %q; got %q", expValue, value)
	}
}
コード例 #3
0
ファイル: int_test.go プロジェクト: achilleasa/usrv
func TestInt32FlagUpdateWithInvalidValue(t *testing.T) {
	defaults.Set("int32-flag-invalid", map[string]string{"flag": "foo"})

	f := Int32("int32-flag-invalid")
	select {
	case <-f.ChangeChan():
		t.Fatal("unexpected configuration change event")
	case <-time.After(1000 * time.Millisecond):
	}
}
コード例 #4
0
ファイル: flag_test.go プロジェクト: achilleasa/usrv
func TestFlagValueMapperError(t *testing.T) {
	defaults.Set("generic-flag-1", map[string]string{"_": "hello"})

	f := &flagImpl{}
	f.init(func(_ string) (interface{}, error) { return nil, errors.New("") }, []string{"generic-flag-1"})

	select {
	case <-f.ChangeChan():
		t.Fatal("unexpected change event")
	case <-time.After(1 * time.Second):
	}
}
コード例 #5
0
ファイル: string_test.go プロジェクト: achilleasa/usrv
func TestStringFlagDynamicUpdate(t *testing.T) {
	defaults.Set("string-flag", map[string]string{"flag": "123"})

	f := String("string-flag")
	select {
	case <-f.ChangeChan():
	case <-time.After(1000 * time.Millisecond):
		t.Fatal("timeout waiting for flag change event")
	}

	expVal := "123"
	val := f.Get()
	if val != expVal {
		t.Fatalf("expected val to be %q; got %q", expVal, val)
	}
}
コード例 #6
0
ファイル: flag_test.go プロジェクト: achilleasa/usrv
func TestFlagDynamicChange(t *testing.T) {
	defaults.Set("generic-flag-1", map[string]string{"_": "hello"})

	f := &flagImpl{}
	f.init(stringMapper, []string{"generic-flag-1"})

	select {
	case <-f.ChangeChan():
	case <-time.After(1 * time.Second):
		t.Fatal("timeout waiting for change evnet")
	}

	expValue := "hello"
	value := f.get().(string)

	if value != expValue {
		t.Fatalf("expected value %q; got %q", expValue, value)
	}
}
コード例 #7
0
ファイル: config_test.go プロジェクト: achilleasa/usrv
func TestEventStream(t *testing.T) {
	expCfg := map[string]string{
		"key1": "value1",
		"key2": "value2",
	}

	defaults.Set("foo", expCfg)

	cfgChan, unsubChan := EventStream("foo")
	defer close(unsubChan)

	select {
	case cfg := <-cfgChan:
		if !reflect.DeepEqual(cfg, expCfg) {
			t.Fatalf("expected received config to be:\n%v\n\ngot:\n%v\n", expCfg, cfg)
		}
	case <-time.After(1 * time.Second):
		t.Fatal("failed to receive config after 100ms")
	}
}
コード例 #8
0
ファイル: int_test.go プロジェクト: achilleasa/usrv
func TestUint32FlagUpdate(t *testing.T) {
	defaults.Set("uint32-flag", map[string]string{"flag": "123"})

	f := Uint32("uint32-flag")
	select {
	case <-f.ChangeChan():
	case <-time.After(1000 * time.Millisecond):
		t.Fatal("timeout waiting for flag change event")
	}

	var expVal uint32 = 123
	val := f.Get()
	if val != expVal {
		t.Fatalf("expected val to be %d; got %d", expVal, val)
	}

	expVal = 999
	f.Set(expVal)
	val = f.Get()
	if val != expVal {
		t.Fatalf("expected val to be %d; got %d", expVal, val)
	}
}
コード例 #9
0
ファイル: bool_test.go プロジェクト: achilleasa/usrv
func TestBoolFlagUpdate(t *testing.T) {
	defaults.Set("bool-flag", map[string]string{"flag": "true"})

	f := Bool("bool-flag")
	select {
	case <-f.ChangeChan():
	case <-time.After(1000 * time.Millisecond):
		t.Fatal("timeout waiting for flag change event")
	}

	expVal := true
	val := f.Get()
	if val != expVal {
		t.Fatalf("expected val to be %v; got %v", expVal, val)
	}

	expVal = false
	f.Set(expVal)
	val = f.Get()
	if val != expVal {
		t.Fatalf("expected val to be %v; got %v", expVal, val)
	}
}
コード例 #10
0
ファイル: float_test.go プロジェクト: achilleasa/usrv
func TestFloat64FlagUpdate(t *testing.T) {
	defaults.Set("float64-flag", map[string]string{"flag": "123.0"})

	f := Float64("float64-flag")
	select {
	case <-f.ChangeChan():
	case <-time.After(1000 * time.Millisecond):
		t.Fatal("timeout waiting for flag change event")
	}

	var expVal float64 = 123.0
	val := f.Get()
	if val != expVal {
		t.Fatalf("expected val to be %f; got %f", expVal, val)
	}

	expVal = 999.0
	f.Set(expVal)
	val = f.Get()
	if val != expVal {
		t.Fatalf("expected val to be %f; got %f", expVal, val)
	}
}