Пример #1
0
func TestPushValues(t *testing.T) {
	values := []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0}
	var b Buffer
	var res []float64

	b = BuildBuffer(10)
	res = b.PushValues(values)
	assert.Nil(t, res)
	assert.Len(t, b.values, len(values))

	b = BuildBuffer(6)
	res = b.PushValues(values)
	assert.NotNil(t, res)
	assert.Len(t, res, len(values))
	assert.Empty(t, b.values)

	b = BuildBuffer(2)
	res = b.PushValues(values)
	assert.NotNil(t, res)
	assert.Len(t, res, len(values))
	assert.Empty(t, b.values)

	b = BuildBuffer(4)
	res = b.PushValues(values)
	assert.NotNil(t, res)
	assert.Len(t, res, b.capacity)
	assert.Len(t, b.values, len(values)-b.capacity)
}
Пример #2
0
func TestPushValue(t *testing.T) {
	value := 1.0
	var b Buffer
	var res []float64

	b = BuildBuffer(10)
	res = b.PushValue(value)
	res = b.PushValue(value)
	res = b.PushValue(value)
	assert.Nil(t, res)
	assert.Len(t, b.values, 3)

	b = BuildBuffer(1)
	res = b.PushValue(value)
	assert.NotNil(t, res)
	assert.Empty(t, b.values)
}
Пример #3
0
func TestEntryPanicf(t *testing.T) {
	errBoom := fmt.Errorf("boom again")

	defer func() {
		p := recover()
		assert.NotNil(t, p)

		switch pVal := p.(type) {
		case *Entry:
			assert.Equal(t, "kaboom true", pVal.Message)
			assert.Equal(t, errBoom, pVal.Data["err"])
		default:
			t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal)
		}
	}()

	logger := New()
	logger.Out = &bytes.Buffer{}
	entry := NewEntry(logger)
	entry.WithField("err", errBoom).Panicf("kaboom %v", true)
}
Пример #4
0
func TestInitializeServiceAvailablePorts(t *testing.T) {
	defer clearServicePorts()

	service1 := "service1"
	ports1 := map[string]string{
		"50100": "50100-50103",
	}
	InitializeServiceAvailablePorts(service1, ports1)
	servicePorts1 := resources.Network.ServicePorts[service1]
	assert.NotNil(t, servicePorts1)
	status1 := servicePorts1.Status["50100"]
	assert.NotNil(t, status1)
	assert.Empty(t, status1.Occupied)
	assert.Len(t, status1.Available, 4)

	service2 := "service2"
	ports2 := map[string]string{
		"50200": "50200",
	}
	InitializeServiceAvailablePorts(service2, ports2)
	servicePorts2 := resources.Network.ServicePorts[service2]
	assert.NotNil(t, servicePorts2)
	status2 := servicePorts2.Status["50200"]
	assert.NotNil(t, status2)
	assert.Empty(t, status2.Occupied)
	assert.Len(t, status2.Available, 1)

	service3 := "service3"
	ports3 := map[string]string{
		"50300": "pippo",
	}
	InitializeServiceAvailablePorts(service3, ports3)
	servicePorts3 := resources.Network.ServicePorts[service3]
	assert.NotNil(t, servicePorts3)
	status3 := servicePorts3.Status["50300"]
	assert.NotNil(t, status3)
	assert.Empty(t, status3.Occupied)
	assert.Empty(t, status3.Available)
}