本文整理匯總了Golang中github.com/eleme/banshee/util/assert.Ok函數的典型用法代碼示例。如果您正苦於以下問題:Golang Ok函數的具體用法?Golang Ok怎麽用?Golang Ok使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Ok函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAnomalyAfterBigAnomaly
// Case anomaly after an anomaly.
func TestAnomalyAfterBigAnomaly(t *testing.T) {
wf := 0.05
leastC := 18
c := New(wf, leastC)
l := genMetrics(120.0, 140.0, 100)
var s *models.State
for _, m := range l {
s = c.Next(s, m)
assert.Ok(t, !m.IsAnomalous())
}
// Give a big anomaly
m := &models.Metric{Value: 2000}
s = c.Next(s, m)
assert.Ok(t, m.IsAnomalousTrendUp())
// Test up and down anomaly
m = &models.Metric{Value: 190}
s = c.Next(s, m)
assert.Ok(t, m.IsAnomalousTrendUp())
m = &models.Metric{Value: 80}
s = c.Next(s, m)
assert.Ok(t, m.IsAnomalousTrendDown())
// Test normal
m = &models.Metric{Value: 130}
s = c.Next(s, m)
assert.Ok(t, !m.IsAnomalous())
}
示例2: TestToFixed
func TestToFixed(t *testing.T) {
assert.Ok(t, ToFixed(1.2345, 2) == "1.23")
assert.Ok(t, ToFixed(10000.12121121, 5) == "10000.12121")
assert.Ok(t, ToFixed(102, 3) == "102")
assert.Ok(t, ToFixed(102.22, 3) == "102.22")
assert.Ok(t, ToFixed(100, 3) == "100")
}
示例3: TestPut
func TestPut(t *testing.T) {
// Open db.
fileName := "db-testing"
db, _ := Open(fileName)
defer os.RemoveAll(fileName)
defer db.Close()
// Put.
m := &models.Metric{
Name: "foo",
Stamp: 1452758773,
Value: 3.14,
Score: 0.1892,
Average: 3.133,
}
err := db.Put(m)
assert.Ok(t, err == nil)
// Must in db
key := encodeKey(m)
value, err := db.db.Get(key, nil)
assert.Ok(t, err == nil)
m1 := &models.Metric{
Name: m.Name,
Stamp: m.Stamp,
}
err = decodeValue(value, m1)
assert.Ok(t, err == nil)
assert.Ok(t, reflect.DeepEqual(m, m1))
}
示例4: TestHitLimit
func TestHitLimit(t *testing.T) {
// Currently disable logging
log.Disable()
defer log.Enable()
//New and add rules.
config := config.New()
config.Interval = 1
rule1 := &models.Rule{Pattern: "a.*.c.d"}
filter := New()
filter.addRule(rule1)
filter.SetHitLimit(config)
for i := 0; i < config.Detector.IntervalHitLimit; i++ {
//hit rule when counter < intervalHitLimit
rules := filter.MatchedRules(&models.Metric{Name: "a.b.c.d"})
assert.Ok(t, 1 == len(rules))
}
//counter over limit, matched rules = 0
rules := filter.MatchedRules(&models.Metric{Name: "a.b.c.d"})
assert.Ok(t, 0 == len(rules))
time.Sleep(time.Second * 2)
//after interval counter is cleared, matched rules = 1
rules = filter.MatchedRules(&models.Metric{Name: "a.b.c.d"})
assert.Ok(t, 1 == len(rules))
}
示例5: TestExampleConfigParsing
func TestExampleConfigParsing(t *testing.T) {
config := New()
err := config.UpdateWithJSONFile("./exampleConfig.json")
assert.Ok(t, err == nil)
defaults := New()
assert.Ok(t, reflect.DeepEqual(config, defaults))
}
示例6: TestDecodeKey
func TestDecodeKey(t *testing.T) {
key := []byte("foo000001f")
m := &models.Metric{}
err := decodeKey(key, m)
assert.Ok(t, err == nil)
assert.Ok(t, m.Name == "foo")
assert.Ok(t, m.Stamp == 36+0xf+horizon)
}
示例7: TestOpen
func TestOpen(t *testing.T) {
fileName := "db-testing"
db, err := Open(fileName)
assert.Ok(t, err == nil)
assert.Ok(t, util.IsFileExist(fileName))
db.Close()
os.RemoveAll(fileName)
}
示例8: TestParseMetric
func TestParseMetric(t *testing.T) {
line := "foo 1449655769 3.14"
m, err := parseMetric(line)
assert.Ok(t, err == nil)
assert.Ok(t, m.Name == "foo")
assert.Ok(t, m.Stamp == uint32(1449655769))
assert.Ok(t, m.Value == 3.14)
}
示例9: TestOpen
func TestOpen(t *testing.T) {
fileName := "db-testing"
db, err := Open(fileName, &Options{288, 300})
defer db.Close()
defer os.RemoveAll(fileName)
assert.Ok(t, err == nil)
assert.Ok(t, util.IsFileExist(fileName))
}
示例10: TestDecodeValue
func TestDecodeValue(t *testing.T) {
m := &models.Metric{}
value := []byte("1.23:0.72:0.79")
err := decodeValue(value, m)
assert.Ok(t, err == nil)
assert.Ok(t, m.Value == 1.23)
assert.Ok(t, m.Score == 0.72)
assert.Ok(t, m.Average == 0.79)
}
示例11: TestDecode
func TestDecode(t *testing.T) {
s := "1450422576:1.2:3.1"
idx := &models.Index{}
err := decode([]byte(s), idx)
assert.Ok(t, err == nil)
assert.Ok(t, idx.Stamp == 1450422576)
assert.Ok(t, idx.Score == 1.2)
assert.Ok(t, idx.Average == 3.1)
}
示例12: TestStampLenEnoughToUse
func TestStampLenEnoughToUse(t *testing.T) {
stamp := uint32(90*365*24*60*60) + horizon
m := &models.Metric{Name: "foo", Stamp: stamp}
key := encodeKey(m)
n := &models.Metric{}
err := decodeKey(key, n)
assert.Ok(t, err == nil)
assert.Ok(t, n.Name == m.Name)
assert.Ok(t, n.Stamp == m.Stamp)
}
示例13: TestMakeEventID
func TestMakeEventID(t *testing.T) {
// Metric with the same name but different stamps.
m1 := &models.Metric{Name: "foo", Stamp: 1456815973}
m2 := &models.Metric{Name: "foo", Stamp: 1456815974}
assert.Ok(t, makeEventID(m1) != makeEventID(m2))
// Metric with the same stamp but different names.
m1 = &models.Metric{Name: "foo", Stamp: 1456815973}
m2 = &models.Metric{Name: "bar", Stamp: 1456815973}
assert.Ok(t, makeEventID(m1) != makeEventID(m2))
}
示例14: TestGenerateID
func TestGenerateID(t *testing.T) {
// Metric with the same name but different stamps.
ev1 := NewEvent(&Metric{Name: "foo", Stamp: 1456815973}, nil)
ev2 := NewEvent(&Metric{Name: "foo", Stamp: 1456815974}, nil)
assert.Ok(t, ev1.ID != ev2.ID)
// Metric with the same stamp but different names.
ev1 = NewEvent(&Metric{Name: "foo", Stamp: 1456815973}, nil)
ev2 = NewEvent(&Metric{Name: "bar", Stamp: 1456815973}, nil)
assert.Ok(t, ev1.ID != ev2.ID)
}
示例15: TestEncoding
func TestEncoding(t *testing.T) {
idx := &models.Index{Stamp: 1450426828, Score: 0.678888, Average: 877.234}
value := encode(idx)
idx1 := &models.Index{}
err := decode(value, idx1)
assert.Ok(t, err == nil)
assert.Ok(t, idx1.Stamp == idx.Stamp)
assert.Ok(t, idx1.Score == 0.67889)
assert.Ok(t, idx1.Average == 877.234)
}