Contains returns true if, for each non-zero-valued field in expected, there exists a corresponding audit log in the mock auditor that matches the expected values. Returns false otherwise.
(t testing.TB, expected database.AuditLog)
| 78 | // there exists a corresponding audit log in the mock auditor that matches |
| 79 | // the expected values. Returns false otherwise. |
| 80 | func (a *MockAuditor) Contains(t testing.TB, expected database.AuditLog) bool { |
| 81 | a.mutex.Lock() |
| 82 | defer a.mutex.Unlock() |
| 83 | for idx, al := range a.auditLogs { |
| 84 | if expected.ID != uuid.Nil && al.ID != expected.ID { |
| 85 | t.Logf("audit log %d: expected ID %s, got %s", idx+1, expected.ID, al.ID) |
| 86 | continue |
| 87 | } |
| 88 | if !expected.Time.IsZero() && expected.Time != al.Time { |
| 89 | t.Logf("audit log %d: expected Time %s, got %s", idx+1, expected.Time, al.Time) |
| 90 | continue |
| 91 | } |
| 92 | if expected.UserID != uuid.Nil && al.UserID != expected.UserID { |
| 93 | t.Logf("audit log %d: expected UserID %s, got %s", idx+1, expected.UserID, al.UserID) |
| 94 | continue |
| 95 | } |
| 96 | if expected.OrganizationID != uuid.Nil && al.OrganizationID != expected.OrganizationID { |
| 97 | t.Logf("audit log %d: expected OrganizationID %s, got %s", idx+1, expected.OrganizationID, al.OrganizationID) |
| 98 | continue |
| 99 | } |
| 100 | if expected.Ip.Valid && al.Ip.IPNet.String() != expected.Ip.IPNet.String() { |
| 101 | t.Logf("audit log %d: expected Ip %s, got %s", idx+1, expected.Ip.IPNet, al.Ip.IPNet) |
| 102 | continue |
| 103 | } |
| 104 | if expected.UserAgent.Valid && al.UserAgent.String != expected.UserAgent.String { |
| 105 | t.Logf("audit log %d: expected UserAgent %s, got %s", idx+1, expected.UserAgent.String, al.UserAgent.String) |
| 106 | continue |
| 107 | } |
| 108 | if expected.ResourceType != "" && expected.ResourceType != al.ResourceType { |
| 109 | t.Logf("audit log %d: expected ResourceType %s, got %s", idx+1, expected.ResourceType, al.ResourceType) |
| 110 | continue |
| 111 | } |
| 112 | if expected.ResourceID != uuid.Nil && expected.ResourceID != al.ResourceID { |
| 113 | t.Logf("audit log %d: expected ResourceID %s, got %s", idx+1, expected.ResourceID, al.ResourceID) |
| 114 | continue |
| 115 | } |
| 116 | if expected.ResourceTarget != "" && expected.ResourceTarget != al.ResourceTarget { |
| 117 | t.Logf("audit log %d: expected ResourceTarget %s, got %s", idx+1, expected.ResourceTarget, al.ResourceTarget) |
| 118 | continue |
| 119 | } |
| 120 | if expected.Action != "" && expected.Action != al.Action { |
| 121 | t.Logf("audit log %d: expected Action %s, got %s", idx+1, expected.Action, al.Action) |
| 122 | continue |
| 123 | } |
| 124 | if len(expected.Diff) > 0 && slices.Compare(expected.Diff, al.Diff) != 0 { |
| 125 | t.Logf("audit log %d: expected Diff %s, got %s", idx+1, string(expected.Diff), string(al.Diff)) |
| 126 | continue |
| 127 | } |
| 128 | if expected.StatusCode != 0 && expected.StatusCode != al.StatusCode { |
| 129 | t.Logf("audit log %d: expected StatusCode %d, got %d", idx+1, expected.StatusCode, al.StatusCode) |
| 130 | continue |
| 131 | } |
| 132 | if len(expected.AdditionalFields) > 0 && slices.Compare(expected.AdditionalFields, al.AdditionalFields) != 0 { |
| 133 | t.Logf("audit log %d: expected AdditionalFields %s, got %s", idx+1, string(expected.AdditionalFields), string(al.AdditionalFields)) |
| 134 | continue |
| 135 | } |
| 136 | if expected.RequestID != uuid.Nil && expected.RequestID != al.RequestID { |
| 137 | t.Logf("audit log %d: expected RequestID %s, got %s", idx+1, expected.RequestID, al.RequestID) |