(t *testing.T)
| 138 | } |
| 139 | |
| 140 | func TestFindOTPById(t *testing.T) { |
| 141 | t.Parallel() |
| 142 | |
| 143 | app, _ := tests.NewTestApp() |
| 144 | defer app.Cleanup() |
| 145 | |
| 146 | if err := tests.StubOTPRecords(app); err != nil { |
| 147 | t.Fatal(err) |
| 148 | } |
| 149 | |
| 150 | scenarios := []struct { |
| 151 | id string |
| 152 | expectError bool |
| 153 | }{ |
| 154 | {"", true}, |
| 155 | {"84nmscqy84lsi1t", true}, // non-otp id |
| 156 | {"superuser2_0", false}, |
| 157 | {"superuser2_4", false}, // expired |
| 158 | {"user1_0", false}, |
| 159 | } |
| 160 | |
| 161 | for _, s := range scenarios { |
| 162 | t.Run(s.id, func(t *testing.T) { |
| 163 | result, err := app.FindOTPById(s.id) |
| 164 | |
| 165 | hasErr := err != nil |
| 166 | if hasErr != s.expectError { |
| 167 | t.Fatalf("Expected hasErr %v, got %v (%v)", s.expectError, hasErr, err) |
| 168 | } |
| 169 | |
| 170 | if hasErr { |
| 171 | return |
| 172 | } |
| 173 | |
| 174 | if result.Id != s.id { |
| 175 | t.Fatalf("Expected record with id %q, got %q", s.id, result.Id) |
| 176 | } |
| 177 | }) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | func TestDeleteAllOTPsByRecord(t *testing.T) { |
| 182 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…