(t *testing.T)
| 13 | var _ checker.Impl = &thoth.ASNChecker{} |
| 14 | |
| 15 | func TestASNChecker(t *testing.T) { |
| 16 | cli := loadSecrets(t) |
| 17 | |
| 18 | asnc := cli.ASNCheckerFor([]uint32{13335}) |
| 19 | |
| 20 | for _, cs := range []struct { |
| 21 | ipAddress string |
| 22 | wantMatch bool |
| 23 | wantError bool |
| 24 | }{ |
| 25 | { |
| 26 | ipAddress: "1.1.1.1", |
| 27 | wantMatch: true, |
| 28 | wantError: false, |
| 29 | }, |
| 30 | { |
| 31 | ipAddress: "2.2.2.2", |
| 32 | wantMatch: false, |
| 33 | wantError: false, |
| 34 | }, |
| 35 | { |
| 36 | ipAddress: "taco", |
| 37 | wantMatch: false, |
| 38 | wantError: false, |
| 39 | }, |
| 40 | { |
| 41 | ipAddress: "127.0.0.1", |
| 42 | wantMatch: false, |
| 43 | wantError: false, |
| 44 | }, |
| 45 | } { |
| 46 | t.Run(fmt.Sprintf("%v", cs), func(t *testing.T) { |
| 47 | req := httptest.NewRequest("GET", "/", nil) |
| 48 | req.Header.Set("X-Real-Ip", cs.ipAddress) |
| 49 | |
| 50 | match, err := asnc.Check(req) |
| 51 | |
| 52 | if match != cs.wantMatch { |
| 53 | t.Errorf("Wanted match: %v, got: %v", cs.wantMatch, match) |
| 54 | } |
| 55 | |
| 56 | switch { |
| 57 | case err != nil && !cs.wantError: |
| 58 | t.Errorf("Did not want error but got: %v", err) |
| 59 | case err == nil && cs.wantError: |
| 60 | t.Error("Wanted error but got none") |
| 61 | } |
| 62 | }) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func BenchmarkWithCache(b *testing.B) { |
| 67 | cli := loadSecrets(b) |
nothing calls this directly
no test coverage detected