Пример #1
0
func (t *AddLogTest) TestBadToken() {
	lg := new(commons.SingleLog)
	lg.Application = "test"
	lg.ApplicationToken = "badToken"
	lg.Level = "ERROR"
	lg.Message = "If you see this there is a problem"
	bJson, _ := json.Marshal(lg)
	println(string(bJson))

	t.Put("/api/log", "application/json", bytes.NewReader(bJson))
	t.AssertContainsRegex("\"success\"[ ]*:[ ]*false")
	t.AssertStatus(200)
	t.AssertContentType("application/json; charset=utf-8")
}
Пример #2
0
func (client *Client) AddLog(log *commonsLog.Log) error {
	var addLogRequestData commonsLog.SingleLog
	copier.Copy(&addLogRequestData, log)
	if len(client.Application) == 0 {
		return NewClientError(ERR_APPLICATION_MANDATORY)
	}
	addLogRequestData.Application = client.Application
	addLogRequestData.ApplicationToken = client.ApplicationToken
	addLogRequestDataJson, err := json.Marshal(addLogRequestData)
	if err != nil {
		return err
	}
	addLogRequest, err := http.NewRequest("PUT", client.Url+"/api/log", bytes.NewReader(addLogRequestDataJson))
	if err != nil {
		return err
	}
	return commonsCall(addLogRequest)
}