(ta TestAccessor, t *testing.T)
| 61 | } |
| 62 | |
| 63 | func testInsertCertificateAndGetCertificate(ta TestAccessor, t *testing.T) { |
| 64 | ta.Truncate() |
| 65 | |
| 66 | expiry := time.Date(2010, time.December, 25, 23, 0, 0, 0, time.UTC) |
| 67 | want := certdb.CertificateRecord{ |
| 68 | PEM: "fake cert data", |
| 69 | Serial: "fake serial", |
| 70 | AKI: fakeAKI, |
| 71 | Status: "good", |
| 72 | Reason: 0, |
| 73 | Expiry: expiry, |
| 74 | } |
| 75 | want.SetMetadata(map[string]interface{}{"k": "v"}) |
| 76 | if err := ta.Accessor.InsertCertificate(want); err != nil { |
| 77 | t.Fatal(err) |
| 78 | } |
| 79 | |
| 80 | rets, err := ta.Accessor.GetCertificate(want.Serial, want.AKI) |
| 81 | if err != nil { |
| 82 | t.Fatal(err) |
| 83 | } |
| 84 | |
| 85 | if len(rets) != 1 { |
| 86 | t.Fatal("should only return one record.") |
| 87 | } |
| 88 | |
| 89 | got := rets[0] |
| 90 | |
| 91 | // reflection comparison with zero time objects are not stable as it seems |
| 92 | if want.Serial != got.Serial || want.Status != got.Status || |
| 93 | want.AKI != got.AKI || !got.RevokedAt.IsZero() || |
| 94 | want.PEM != got.PEM || !roughlySameTime(got.Expiry, expiry) { |
| 95 | t.Errorf("want Certificate %+v, got %+v", want, got) |
| 96 | } |
| 97 | gotMeta, err := got.GetMetadata() |
| 98 | if err != nil { |
| 99 | t.Fatal(err) |
| 100 | } |
| 101 | expected := map[string]interface{}{"k": "v"} |
| 102 | if !reflect.DeepEqual(gotMeta, expected) { |
| 103 | t.Fatalf("expected: %+v, got: %+v", expected, gotMeta) |
| 104 | } |
| 105 | |
| 106 | unexpired, err := ta.Accessor.GetUnexpiredCertificates() |
| 107 | |
| 108 | if err != nil { |
| 109 | t.Fatal(err) |
| 110 | } |
| 111 | |
| 112 | if len(unexpired) != 0 { |
| 113 | t.Error("should not have unexpired certificate record") |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | func testInsertCertificateAndGetUnexpiredCertificate(ta TestAccessor, t *testing.T) { |
| 118 | ta.Truncate() |
no test coverage detected
searching dependent graphs…