(t *testing.T)
| 153 | } |
| 154 | |
| 155 | func TestRevokeAPIKey_Success(t *testing.T) { |
| 156 | db, mock, err := sqlmock.New() |
| 157 | assert.NoError(t, err) |
| 158 | defer func() { _ = db.Close() }() |
| 159 | |
| 160 | ds := Datasource{Conn: db} |
| 161 | |
| 162 | apiKeyID := "api_key_123" |
| 163 | ownerID := "owner123" |
| 164 | hashedKey := "some-hashed-key-value" |
| 165 | |
| 166 | selectRow := sqlmock.NewRows([]string{"key"}). |
| 167 | AddRow(hashedKey) |
| 168 | |
| 169 | mock.ExpectQuery("SELECT.*FROM ledgerforge.api_keys.*WHERE api_key_id.*AND owner_id.*"). |
| 170 | WithArgs(apiKeyID, ownerID). |
| 171 | WillReturnRows(selectRow) |
| 172 | |
| 173 | mock.ExpectExec("UPDATE ledgerforge.api_keys.*SET is_revoked.*WHERE api_key_id.*AND owner_id.*"). |
| 174 | WithArgs(sqlmock.AnyArg(), apiKeyID, ownerID). |
| 175 | WillReturnResult(sqlmock.NewResult(0, 1)) |
| 176 | |
| 177 | err = ds.RevokeAPIKey(context.Background(), apiKeyID, ownerID) |
| 178 | assert.NoError(t, err) |
| 179 | |
| 180 | err = mock.ExpectationsWereMet() |
| 181 | assert.NoError(t, err) |
| 182 | } |
| 183 | |
| 184 | func TestRevokeAPIKey_NotFound(t *testing.T) { |
| 185 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected