Beispiel #1
0
func saveOrUpdateMonitor(result string) error {
	var nats entity.NatsResult
	err := json.Unmarshal([]byte(result), &nats)

	if err != nil {
		return err
	}

	monitor := entity.Monitor{}
	monitor.AgentId = nats.Value.AgentId
	monitor.Index = nats.Value.Index
	monitor.JobName = nats.Value.Job.Name
	monitor.JobState = nats.Value.JobState
	monitor.Updated = time.Now()
	monitor.Value = result

	err = monitor.SaveOrUpdate()
	return err
}
	        }
	    }
	}`
	var nats entity.NatsResult
	BeforeEach(func() {
		err := json.Unmarshal([]byte(result), &nats)
		fmt.Println(err)
	})

	It("Testing Insert OpsMonitor", func() {
		monitor := entity.Monitor{}
		monitor.AgentId = nats.Value.AgentId
		monitor.Index = nats.Value.Index
		monitor.JobName = nats.Value.Job.Name
		monitor.JobState = nats.Value.JobState
		monitor.Value = result

		errors := monitor.Save()

		Expect(errors).NotTo(HaveOccurred())

		errors = monitor.Delete()

		Expect(errors).NotTo(HaveOccurred())
	})

	It("Testing Load OpsMonitor", func() {
		sq, err := orm.NewOrm().Raw("insert into monitor (updated) values(?)", time.Now()).Exec()
		Expect(err).NotTo(HaveOccurred())

		id, _ := sq.LastInsertId()