本文整理汇总了Golang中github.com/percona/percona-agent/test.IsDeeply函数的典型用法代码示例。如果您正苦于以下问题:Golang IsDeeply函数的具体用法?Golang IsDeeply怎么用?Golang IsDeeply使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsDeeply函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestGetConfig
func (s *AgentTestSuite) TestGetConfig(t *C) {
cmd := &proto.Cmd{
Ts: time.Now(),
User: "daniel",
Cmd: "GetConfig",
Service: "agent",
}
s.sendChan <- cmd
got := test.WaitReply(s.recvChan)
t.Assert(len(got), Equals, 1)
gotConfig := []proto.AgentConfig{}
if err := json.Unmarshal(got[0].Data, &gotConfig); err != nil {
t.Fatal(err)
}
config := *s.config
config.Links = nil
bytes, _ := json.Marshal(config)
expect := []proto.AgentConfig{
{
InternalService: "agent",
Config: string(bytes),
Running: true,
},
}
if ok, diff := test.IsDeeply(gotConfig, expect); !ok {
t.Logf("%+v", gotConfig)
t.Error(diff)
}
}
示例2: TestC002
func (s *AggregatorTestSuite) TestC002(t *C) {
interval := int64(300)
a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool)
go a.Start()
defer a.Stop()
// Ts in c002-1 is 2009-11-10 23:00:00.
t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
for i := 1; i <= 5; i++ {
file := fmt.Sprintf("%s/c002-%d.json", sample, i)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
}
// Next interval causes 1st to be reported.
file := fmt.Sprintf("%s/c002-n.json", sample)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
got := test.WaitMmReport(s.dataChan)
t.Assert(got, NotNil)
t.Check(got.Ts, Equals, t1)
t.Check(uint64(got.Duration), Equals, uint64(interval))
expect := &mm.Report{}
if err := test.LoadMmReport(sample+"/c002r.json", expect); err != nil {
t.Fatal("c002r.json ", err)
}
if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok {
t.Fatal(diff)
}
}
示例3: TestAddWatcher
func (s *ManagerTestSuite) TestAddWatcher(t *check.C) {
now = int64(1380330697385120263) // Fri Sep 27 18:11:37.385120 -0700 PDT 2013
s.tickerFactory.Set([]ticker.Ticker{s.mockTicker})
m := ticker.NewClock(s.tickerFactory, nowFunc)
c := make(chan time.Time)
m.Add(c, 79, true)
if !test.WaitState(s.mockTicker.RunningChan) {
t.Error("Starts ticker")
}
if ok, diff := test.IsDeeply(s.tickerFactory.Made, []uint{79}); !ok {
t.Errorf("Make 79s ticker, got %#v", diff)
}
if len(s.mockTicker.Added) == 0 {
t.Error("Ticker added watcher")
}
// Manager should call ticker's ETA() to return time to next tick.
d := m.ETA(c)
if d != 0.1 {
t.Error("clock.Manager.ETA()")
}
m.Remove(c)
}
示例4: TestProcMeminfo001
func (s *ProcMeminfoTestSuite) TestProcMeminfo001(t *C) {
m := system.NewMonitor("", &system.Config{}, s.logger)
content, err := ioutil.ReadFile(sample + "/proc/meminfo001.txt")
if err != nil {
t.Fatal(err)
}
got, err := m.ProcMeminfo(content)
if err != nil {
t.Fatal(err)
}
// Remember: the order of this array must match order in which each
// stat appears in the input file:
expect := []mm.Metric{
{Name: "memory/MemTotal", Type: "gauge", Number: 8046892}, // ok
{Name: "memory/MemFree", Type: "gauge", Number: 5273644}, // ok
{Name: "memory/Buffers", Type: "gauge", Number: 300684}, // ok
{Name: "memory/Cached", Type: "gauge", Number: 946852}, // ok
{Name: "memory/SwapCached", Type: "gauge", Number: 0}, // ok
{Name: "memory/Active", Type: "gauge", Number: 1936436}, // ok
{Name: "memory/Inactive", Type: "gauge", Number: 598916}, // ok
{Name: "memory/SwapTotal", Type: "gauge", Number: 8253436}, // ok
{Name: "memory/SwapFree", Type: "gauge", Number: 8253436}, // ok
{Name: "memory/Dirty", Type: "gauge", Number: 0}, // ok
}
if same, diff := test.IsDeeply(got, expect); !same {
test.Dump(got)
t.Error(diff)
}
}
示例5: TestProcVmstat001
func (s *ProcVmstatTestSuite) TestProcVmstat001(t *C) {
m := system.NewMonitor("", &system.Config{}, s.logger)
content, err := ioutil.ReadFile(sample + "/proc/vmstat001.txt")
if err != nil {
t.Fatal(err)
}
got, err := m.ProcVmstat(content)
if err != nil {
t.Fatal(err)
}
// Remember: the order of this array must match order in which each
// stat appears in the input file:
expect := []mm.Metric{
{Name: "vmstat/numa_hit", Type: "counter", Number: 42594095}, // ok
{Name: "vmstat/numa_miss", Type: "counter", Number: 0}, // ok
{Name: "vmstat/numa_foreign", Type: "counter", Number: 0}, // ok
{Name: "vmstat/numa_interleave", Type: "counter", Number: 7297}, // ok
{Name: "vmstat/numa_local", Type: "counter", Number: 42594095}, // ok
{Name: "vmstat/numa_other", Type: "counter", Number: 0}, // ok
{Name: "vmstat/pgpgin", Type: "counter", Number: 646645}, // ok
{Name: "vmstat/pgpgout", Type: "counter", Number: 5401659}, // ok
{Name: "vmstat/pswpin", Type: "counter", Number: 0}, // ok
{Name: "vmstat/pswpout", Type: "counter", Number: 0}, // ok
}
if same, diff := test.IsDeeply(got, expect); !same {
test.Dump(got)
t.Error(diff)
}
}
示例6: TestInit
func (s *RepoTestSuite) TestInit(t *C) {
im := instance.NewRepo(s.logger, s.configDir, s.api)
t.Assert(im, NotNil)
err := im.Init()
t.Check(err, IsNil)
err = test.CopyFile(test.RootDir+"/mm/config/mysql-1.conf", s.configDir)
t.Assert(err, IsNil)
err = im.Init()
t.Assert(err, IsNil)
mysqlIt := &proto.MySQLInstance{}
err = im.Get("mysql", 1, mysqlIt)
t.Assert(err, IsNil)
expect := &proto.MySQLInstance{
Id: 1,
Hostname: "db1",
DSN: "user:[email protected]:(127.0.0.1:3306)",
Distro: "Percona Server",
Version: "5.6.16",
}
if same, diff := test.IsDeeply(mysqlIt, expect); !same {
test.Dump(mysqlIt)
test.Dump(expect)
t.Error(diff)
}
}
示例7: TestC000
// All zero values
func (s *AggregatorTestSuite) TestC000(t *C) {
interval := int64(60)
a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool)
go a.Start()
defer a.Stop()
// Ts in c000 is 2009-11-10 23:00:00.
t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
file := sample + "/c000.json"
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
file = sample + "/c000-n.json"
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
got := test.WaitMmReport(s.dataChan)
t.Assert(got, NotNil)
t.Check(got.Ts, Equals, t1)
t.Check(uint64(got.Duration), Equals, uint64(interval))
expect := &mm.Report{}
if err := test.LoadMmReport(sample+"/c000r.json", expect); err != nil {
t.Fatal("c000r.json ", err)
}
if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok {
t.Fatal(diff)
}
}
示例8: TestStartStopManager
func (s *ManagerTestSuite) TestStartStopManager(t *C) {
/**
* mm is a proxy manager for monitors, so it's always running.
* It should implement the service manager interface anyway,
* but it doesn't actually start or stop. Its main work is done
* in Handle, starting and stopping monitors (tested later).
*/
mrm := mock.NewMrmsMonitor()
m := mm.NewManager(s.logger, s.factory, s.clock, s.spool, s.im, mrm)
if m == nil {
t.Fatal("Make new mm.Manager")
}
// It shouldn't have added a tickChan yet.
if len(s.clock.Added) != 0 {
t.Error("tickChan not added yet")
}
// First the API marshals an mm.Config.
config := &mm.Config{
ServiceInstance: proto.ServiceInstance{
Service: "mysql",
InstanceId: 1,
},
Collect: 1,
Report: 60,
// No monitor-specific config
}
err := pct.Basedir.WriteConfig("mm-mysql-1", config)
t.Assert(err, IsNil)
// The agent calls mm.Start().
err = m.Start()
t.Assert(err, IsNil)
// There is a monitor so there should be tickers.
if ok, diff := test.IsDeeply(s.clock.Added, []uint{1}); !ok {
test.Dump(s.clock.Added)
t.Errorf("Does not add tickChan, got %#v", diff)
}
// Its status should be "Running".
status := m.Status()
t.Check(status["mm"], Equals, "Running")
// Can't start mm twice.
err = m.Start()
t.Check(err, Not(Equals), "")
// Stopping should be idempotent.
err = m.Stop()
t.Check(err, IsNil)
err = m.Stop()
t.Check(err, IsNil)
status = m.Status()
t.Check(status["mm"], Equals, "Stopped")
}
示例9: TestLoadConfig
func (s *AgentTestSuite) TestLoadConfig(t *C) {
// Load a partial config to make sure LoadConfig() works in general but also
// when the config has missing options (which is normal).
os.Remove(s.configFile)
test.CopyFile(sample+"/config001.json", s.configFile)
bytes, err := agent.LoadConfig()
t.Assert(err, IsNil)
got := &agent.Config{}
if err := json.Unmarshal(bytes, got); err != nil {
t.Fatal(err)
}
expect := &agent.Config{
AgentUuid: "abc-123-def",
ApiHostname: agent.DEFAULT_API_HOSTNAME,
ApiKey: "123",
Keepalive: agent.DEFAULT_KEEPALIVE,
PidFile: agent.DEFAULT_PIDFILE,
}
if same, diff := test.IsDeeply(got, expect); !same {
// @todo: if expect is not ptr, IsDeeply dies with "got ptr, expected struct"
test.Dump(got)
t.Error(diff)
}
// Load a config with all options to make sure LoadConfig() hasn't missed any.
os.Remove(s.configFile)
test.CopyFile(sample+"/full_config.json", s.configFile)
bytes, err = agent.LoadConfig()
t.Assert(err, IsNil)
got = &agent.Config{}
if err := json.Unmarshal(bytes, got); err != nil {
t.Fatal(err)
}
expect = &agent.Config{
ApiHostname: "agent hostname",
ApiKey: "api key",
AgentUuid: "agent uuid",
Keepalive: agent.DEFAULT_KEEPALIVE,
PidFile: "pid file",
}
if same, diff := test.IsDeeply(got, expect); !same {
test.Dump(got)
t.Error(diff)
}
}
示例10: TestOfflineBuffering
func (s *RelayTestSuite) TestOfflineBuffering(t *C) {
l := s.logger
// We're going to cause the relay's client Recv() to get an error
// which will cause the relay to connect again. We block this 2nd
// connect by blocking this chan. End result: relay remains offline.
s.client.SetConnectChan(s.connectChan)
doneChan := make(chan bool, 1)
go func() {
s.client.RecvError <- io.EOF
doneChan <- true
}()
// Wait for the relay to recv the recv error.
<-doneChan
// Wait for the relay to call client.Connect().
<-s.connectChan
// Double-check that relay is offline.
if !test.WaitStatus(1, s.relay, "ws", "Disconnected") {
t.Fatal("Relay connects")
}
// Relay is offline and trying to connect again in another goroutine.
// These entries should therefore not be sent. There's a minor race
// condition: when relay goes offline, it sends an internal log entry.
// Sometimes we get that here (Service="log") and sometimes not
// (len(got)==0). Either condition is correct for this test.
l.Error("err1")
l.Error("err2")
got := test.WaitLog(s.recvChan, 0)
if len(got) > 0 && got[0].Service != "log" {
t.Errorf("Log entries are not sent while offline: %+v", got)
}
// Unblock the relay's connect attempt.
s.connectChan <- true
if !test.WaitStatus(1, s.relay, "ws", "Connected") {
t.Fatal("Relay connects")
}
// Wait for the relay resend what it had ^ buffered.
got = test.WaitLog(s.recvChan, 3)
expect := []proto.LogEntry{
{Ts: test.Ts, Level: proto.LOG_WARNING, Service: "log", Msg: "connected: false"},
{Ts: test.Ts, Level: proto.LOG_ERROR, Service: "test", Msg: "err1"},
{Ts: test.Ts, Level: proto.LOG_ERROR, Service: "test", Msg: "err2"},
{Ts: test.Ts, Level: proto.LOG_WARNING, Service: "log", Msg: "connected: true"},
}
if same, diff := test.IsDeeply(got, expect); !same {
t.Error(diff)
}
}
示例11: TestAddRemove
func (s *RepoTestSuite) TestAddRemove(t *C) {
im := instance.NewRepo(s.logger, s.configDir, s.api)
t.Assert(im, NotNil)
t.Check(test.FileExists(s.configDir+"/mysql-1.conf"), Equals, false)
mysqlIt := &proto.MySQLInstance{
Id: 1,
Hostname: "db1",
DSN: "user:[email protected]:(127.0.0.1:3306)",
Distro: "Percona Server",
Version: "5.6.16",
}
data, err := json.Marshal(mysqlIt)
t.Assert(err, IsNil)
err = im.Add("mysql", 1, data, true)
t.Assert(err, IsNil)
t.Check(test.FileExists(s.configDir+"/mysql-1.conf"), Equals, true)
got := &proto.MySQLInstance{}
err = im.Get("mysql", 1, got)
t.Assert(err, IsNil)
if same, diff := test.IsDeeply(got, mysqlIt); !same {
t.Error(diff)
}
data, err = ioutil.ReadFile(s.configDir + "/mysql-1.conf")
t.Assert(err, IsNil)
got = &proto.MySQLInstance{}
err = json.Unmarshal(data, got)
t.Assert(err, IsNil)
if same, diff := test.IsDeeply(got, mysqlIt); !same {
t.Error(diff)
}
im.Remove("mysql", 1)
t.Check(test.FileExists(s.configDir+"/mysql-1.conf"), Equals, false)
}
示例12: Test500Error
func (s *SenderTestSuite) Test500Error(t *C) {
spool := mock.NewSpooler(nil)
spool.FilesOut = []string{"file1", "file2", "file3"}
spool.DataOut = map[string][]byte{
"file1": []byte("file1"),
"file2": []byte("file2"),
"file3": []byte("file3"),
}
sender := data.NewSender(s.logger, s.client)
err := sender.Start(spool, s.tickerChan, 5, false)
t.Assert(err, IsNil)
s.tickerChan <- time.Now()
got := test.WaitBytes(s.dataChan)
if same, diff := test.IsDeeply(got[0], []byte("file1")); !same {
t.Error(diff)
}
// 3 files before API error.
t.Check(len(spool.DataOut), Equals, 3)
// Simulate API error.
select {
case s.respChan <- &proto.Response{Code: 503}:
case <-time.After(500 * time.Millisecond):
t.Error("Sender receives prot.Response after sending data")
}
// Wait for it to finsih and return.
if !test.WaitStatusPrefix(data.MAX_SEND_ERRORS*data.CONNECT_ERROR_WAIT, sender, "data-sender", "Idle") {
t.Fatal("Timeout waiting for data-sender status=Idle")
}
// Still 3 files after API error.
t.Check(len(spool.DataOut), Equals, 3)
t.Check(len(spool.RejectedFiles), Equals, 0)
// There's only 1 call to SendBytes because after an API error
// the send stops immediately.
trace := test.DrainTraceChan(s.client.TraceChan)
t.Check(trace, DeepEquals, []string{
"ConnectOnce",
"SendBytes",
"Recv",
"DisconnectOnce",
})
err = sender.Stop()
t.Assert(err, IsNil)
}
示例13: TestSendData
func (s *SenderTestSuite) TestSendData(t *C) {
spool := mock.NewSpooler(nil)
slow001, err := ioutil.ReadFile(sample + "slow001.json")
if err != nil {
t.Fatal(err)
}
spool.FilesOut = []string{"slow001.json"}
spool.DataOut = map[string][]byte{"slow001.json": slow001}
sender := data.NewSender(s.logger, s.client)
err = sender.Start(spool, s.tickerChan, 5, false)
if err != nil {
t.Fatal(err)
}
data := test.WaitBytes(s.dataChan)
if len(data) != 0 {
t.Errorf("No data sent before tick; got %+v", data)
}
s.tickerChan <- time.Now()
data = test.WaitBytes(s.dataChan)
if same, diff := test.IsDeeply(data[0], slow001); !same {
t.Error(diff)
}
t.Check(len(spool.DataOut), Equals, 1)
select {
case s.respChan <- &proto.Response{Code: 200}:
case <-time.After(500 * time.Millisecond):
t.Error("Sender receives prot.Response after sending data")
}
// Sender should include its websocket client status. We're using a mock ws client
// which reports itself as "data-client: ok".
status := sender.Status()
t.Check(status["data-client"], Equals, "ok")
err = sender.Stop()
t.Assert(err, IsNil)
t.Check(len(spool.DataOut), Equals, 0)
t.Check(len(spool.RejectedFiles), Equals, 0)
}
示例14: TestC003
// COUNTER
func (s *AggregatorTestSuite) TestC003(t *C) {
interval := int64(5)
a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool)
go a.Start()
defer a.Stop()
// Ts in c003 is 2009-11-10 23:00:00.
t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
for i := 1; i <= 5; i++ {
file := fmt.Sprintf("%s/c003-%d.json", sample, i)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
}
// Next interval causes 1st to be reported.
file := fmt.Sprintf("%s/c003-n.json", sample)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
/**
* Pretend we're monitoring Bytes_sents every second:
* first val = 100
* prev this diff val/s
* next val 100 200 100 100
* next val 200 400 200 200
* next val 400 800 400 400
* next val 800 1600 800 800
*
* So min bytes/s = 100, max = 800, avg = 375. These are
* the values in c003r.json.
*/
got := test.WaitMmReport(s.dataChan)
t.Assert(got, NotNil)
t.Check(got.Ts, Equals, t1)
t.Check(uint64(got.Duration), Equals, uint64(interval))
expect := &mm.Report{}
if err := test.LoadMmReport(sample+"/c003r.json", expect); err != nil {
t.Fatal("c003r.json ", err)
}
if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok {
t.Fatal(diff)
}
}
示例15: TestGetAllConfigs
func (s *AgentTestSuite) TestGetAllConfigs(t *C) {
cmd := &proto.Cmd{
Ts: time.Now(),
User: "daniel",
Cmd: "GetAllConfigs",
Service: "agent",
}
s.sendChan <- cmd
got := test.WaitReply(s.recvChan)
t.Assert(len(got), Equals, 1)
reply := got[0]
t.Check(reply.Error, Equals, "")
t.Assert(reply.Data, Not(HasLen), 0)
gotConfigs := []proto.AgentConfig{}
err := json.Unmarshal(reply.Data, &gotConfigs)
t.Assert(err, IsNil)
bytes, _ := json.Marshal(s.config)
sort.Sort(test.ByInternalService(gotConfigs))
expectConfigs := []proto.AgentConfig{
{
InternalService: "agent",
Config: string(bytes),
Running: true,
},
{
InternalService: "mm",
Config: `{"Foo":"bar"}`,
Running: false,
},
{
InternalService: "qan",
Config: `{"Foo":"bar"}`,
Running: false,
},
}
if ok, diff := test.IsDeeply(gotConfigs, expectConfigs); !ok {
test.Dump(gotConfigs)
t.Error(diff)
}
}