本文整理匯總了Golang中github.com/elleFlorio/gru/Godeps/_workspace/src/github.com/stretchr/testify/assert.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestCreatePortBindings
func TestCreatePortBindings(t *testing.T) {
service1 := "service1"
ports1 := map[string]string{
"50100": "50100",
}
service2 := "service2"
ports2 := map[string]string{
"50200": "50200",
}
service3 := "service3"
resources.InitializeServiceAvailablePorts(service1, ports1)
resources.InitializeServiceAvailablePorts(service2, ports2)
bindings1 := createPortBindings(service1)
assert.Len(t, bindings1, 1)
assert.NotEmpty(t, bindings1["50100/tcp"])
assert.Equal(t, "50100", bindings1["50100/tcp"][0].HostPort)
bindings2 := createPortBindings(service2)
assert.Len(t, bindings2, 1)
assert.NotEmpty(t, bindings2["50200/tcp"])
assert.Equal(t, "50200", bindings2["50200/tcp"][0].HostPort)
bindings3 := createPortBindings(service3)
assert.Empty(t, bindings3)
}
示例2: TestWithFieldsShouldAllowAssignments
func TestWithFieldsShouldAllowAssignments(t *testing.T) {
var buffer bytes.Buffer
var fields Fields
logger := New()
logger.Out = &buffer
logger.Formatter = new(JSONFormatter)
localLog := logger.WithFields(Fields{
"key1": "value1",
})
localLog.WithField("key2", "value2").Info("test")
err := json.Unmarshal(buffer.Bytes(), &fields)
assert.Nil(t, err)
assert.Equal(t, "value2", fields["key2"])
assert.Equal(t, "value1", fields["key1"])
buffer = bytes.Buffer{}
fields = Fields{}
localLog.Info("test")
err = json.Unmarshal(buffer.Bytes(), &fields)
assert.Nil(t, err)
_, ok := fields["key2"]
assert.Equal(t, false, ok)
assert.Equal(t, "value1", fields["key1"])
}
示例3: TestDeltaElement
func TestDeltaElement(t *testing.T) {
var plc *data.Policy
var threshold float64
var policies []data.Policy
targets := []string{"pippo"}
actions := map[string][]enum.Action{
"pippo": []enum.Action{enum.START},
}
policies = []data.Policy{
data.CreateMockPolicy("p1", 0.1, targets, actions),
data.CreateMockPolicy("p2", 0.4, targets, actions),
data.CreateMockPolicy("p3", 0.6, targets, actions),
data.CreateMockPolicy("p4", 0.2, targets, actions),
}
threshold = 0.4
plc = deltaElement(policies, threshold)
assert.Equal(t, "p3", plc.Name)
threshold = 0.8
plc = deltaElement(policies, threshold)
assert.Equal(t, "p3", plc.Name)
}
示例4: TestComputeServicesMetrics
func TestComputeServicesMetrics(t *testing.T) {
defer resetMetrics()
instMetrics := make(map[string]data.MetricData)
instMetrics["instance1_1"] = data.MetricData{
BaseMetrics: map[string]float64{
enum.METRIC_CPU_AVG.ToString(): 0.4,
enum.METRIC_MEM_AVG.ToString(): 0.4,
},
}
instMetrics["instance1_2"] = data.MetricData{
BaseMetrics: map[string]float64{
enum.METRIC_CPU_AVG.ToString(): 0.6,
enum.METRIC_MEM_AVG.ToString(): 0.6,
},
}
instMetrics["instance2_1"] = data.MetricData{
BaseMetrics: map[string]float64{
enum.METRIC_CPU_AVG.ToString(): 0.5,
enum.METRIC_MEM_AVG.ToString(): 0.5,
},
}
servicesMetrics["service1"].UserMetrics["response_time"] = []float64{1000, 2000, 3000, 4000, 5000}
servicesMetrics["service2"].UserMetrics["response_time"] = []float64{1000, 2000, 3000, 4000, 5000}
serviceMet := computeServicesMetrics(instMetrics)
assert.NotEmpty(t, serviceMet)
assert.InEpsilon(t, 0.5, serviceMet["service1"].BaseMetrics[enum.METRIC_CPU_AVG.ToString()], 0.0001)
assert.InEpsilon(t, 0.5, serviceMet["service2"].BaseMetrics[enum.METRIC_CPU_AVG.ToString()], 0.0001)
assert.Equal(t, 0.0, serviceMet["service3"].BaseMetrics[enum.METRIC_CPU_AVG.ToString()])
assert.Equal(t, 0.0, serviceMet["service3"].BaseMetrics[enum.METRIC_MEM_AVG.ToString()])
assert.Equal(t, 3000.0, serviceMet["service1"].UserMetrics["response_time"])
assert.Equal(t, 3000.0, serviceMet["service2"].UserMetrics["response_time"])
}
示例5: TestGetCoresAvailable
func TestGetCoresAvailable(t *testing.T) {
defer freeCores()
var assigned string
var ok bool
req := 2
id := "pippo"
assigned, ok = GetCoresAvailable(req)
assert.True(t, ok)
assert.Equal(t, "0,1", assigned)
freeCores()
assignSpecificCores([]int{1, 3}, id)
assigned, ok = GetCoresAvailable(req)
assert.True(t, ok)
assert.Equal(t, "0,2", assigned)
freeCores()
req_wrong := c_NCORES + 1
assigned, ok = GetCoresAvailable(req_wrong)
assert.False(t, ok)
assert.Equal(t, "", assigned)
}
示例6: TestMean
func TestMean(t *testing.T) {
values := []float64{2, 4, 6}
valuesEmpty := []float64{}
assert.Equal(t, 4.0, Mean(values))
assert.Equal(t, 0.0, Mean(valuesEmpty))
}
示例7: TestWarn
func TestWarn(t *testing.T) {
LogAndAssertJSON(t, func(log *Logger) {
log.Warn("test")
}, func(fields Fields) {
assert.Equal(t, fields["msg"], "test")
assert.Equal(t, fields["level"], "warning")
})
}
示例8: TestInfo
func TestInfo(t *testing.T) {
LogAndAssertJSON(t, func(log *Logger) {
log.Info("test")
}, func(fields Fields) {
assert.Equal(t, fields["msg"], "test")
assert.Equal(t, fields["level"], "info")
})
}
示例9: TestUserSuppliedLevelFieldHasPrefix
func TestUserSuppliedLevelFieldHasPrefix(t *testing.T) {
LogAndAssertJSON(t, func(log *Logger) {
log.WithField("level", 1).Info("test")
}, func(fields Fields) {
assert.Equal(t, fields["level"], "info")
assert.Equal(t, fields["fields.level"], 1.0) // JSON has floats only
})
}
示例10: TestUserSuppliedMsgFieldHasPrefix
func TestUserSuppliedMsgFieldHasPrefix(t *testing.T) {
LogAndAssertJSON(t, func(log *Logger) {
log.WithField("msg", "hello").Info("test")
}, func(fields Fields) {
assert.Equal(t, fields["msg"], "test")
assert.Equal(t, fields["fields.msg"], "hello")
})
}
示例11: TestGetters
func TestGetters(t *testing.T) {
defer storage.DeleteAllData(enum.ANALYTICS)
data.SaveMockAnalytics()
analytics := data.CreateMockAnalytics()
assert.Equal(t, analytics, GetAnalytics())
assert.Equal(t, analytics.Service["service1"], GetServiceAnalytics("service1"))
assert.Equal(t, analytics.Service, GetServicesAnalytics())
assert.Equal(t, analytics.System, GetSystemAnalytics())
}
示例12: TestCreateMemory
func TestCreateMemory(t *testing.T) {
notSet := ""
mem1 := "1G"
var memory int64
memory = createMemory(notSet)
assert.Equal(t, int64(0), memory)
memory = createMemory(mem1)
assert.Equal(t, 1024, 1024)
}
示例13: TestComputeInstanceCpuPerc
func TestComputeInstanceCpuPerc(t *testing.T) {
mockInstCpus := []float64{10000, 20000, 30000, 40000, 50000, 60000}
mockSysCpus := []float64{1000000, 1100000, 1200000, 1300000, 1400000, 1500000}
mockPerc := computeInstanceCpuPerc(mockInstCpus, mockSysCpus)
assert.Equal(t, 0.1, mockPerc)
mockInstCpus = []float64{10000, 10000, 10000, 10000, 10000, 10000}
mockPerc = computeInstanceCpuPerc(mockInstCpus, mockSysCpus)
assert.Equal(t, 0.0, mockPerc)
}
示例14: TestHookFires
func TestHookFires(t *testing.T) {
hook := new(TestHook)
LogAndAssertJSON(t, func(log *Logger) {
log.Hooks.Add(hook)
assert.Equal(t, hook.Fired, false)
log.Print("test")
}, func(fields Fields) {
assert.Equal(t, hook.Fired, true)
})
}
示例15: TestGetFreeSlots
func TestGetFreeSlots(t *testing.T) {
b := BuildBuffer(10)
values := []float64{1, 2, 3}
var f int
f = b.GetFreeSlots()
assert.Equal(t, b.capacity, f)
b.values = append(b.values, values...)
f = b.GetFreeSlots()
assert.Equal(t, b.capacity-len(b.values), f)
}