func (*AuditSuite) TestPutAuditEntry_ValidateAuditEntry(c *gc.C) { var auditEntry audit.AuditEntry // Don't care what the error is; just that it's not valid. validationErr := auditEntry.Validate() c.Assert(validationErr, gc.NotNil) putAuditEntry := stateaudit.PutAuditEntryFn("", nil) err := putAuditEntry(auditEntry) c.Check(err, gc.ErrorMatches, validationErr.Error()) }
func (*AuditSuite) TestPutAuditEntry_PropagatesWriteError(c *gc.C) { const errMsg = "my error" insertDocs := func(string, ...interface{}) error { return errors.New(errMsg) } putAuditEntry := stateaudit.PutAuditEntryFn("audit.log", insertDocs) uuid, err := utils.NewUUID() c.Assert(err, jc.ErrorIsNil) auditEntry := audit.AuditEntry{ JujuServerVersion: version.MustParse("1.0.0"), ModelUUID: uuid.String(), Timestamp: coretesting.NonZeroTime().UTC(), RemoteAddress: "8.8.8.8", OriginType: "user", OriginName: "bob", Operation: "status", } c.Assert(auditEntry.Validate(), jc.ErrorIsNil) err = putAuditEntry(auditEntry) c.Check(err, gc.ErrorMatches, errMsg) }