TestDistributor invokes the different methods on the Distributor type and verifies the results.
(t *testing.T)
| 44 | // TestDistributor invokes the different methods on the Distributor type and |
| 45 | // verifies the results. |
| 46 | func (s) TestDistributor(t *testing.T) { |
| 47 | dist := NewDistributor() |
| 48 | |
| 49 | // Read cert/key files from testdata. |
| 50 | km1 := loadKeyMaterials(t, "x509/server1_cert.pem", "x509/server1_key.pem", "x509/client_ca_cert.pem") |
| 51 | km2 := loadKeyMaterials(t, "x509/server2_cert.pem", "x509/server2_key.pem", "x509/client_ca_cert.pem") |
| 52 | |
| 53 | // Push key material into the distributor and make sure that a call to |
| 54 | // KeyMaterial() returns the expected key material, with both the local |
| 55 | // certs and root certs. |
| 56 | dist.Set(km1, nil) |
| 57 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 58 | defer cancel() |
| 59 | if err := readAndVerifyKeyMaterial(ctx, dist, km1); err != nil { |
| 60 | t.Fatal(err) |
| 61 | } |
| 62 | |
| 63 | // Push new key material into the distributor and make sure that a call to |
| 64 | // KeyMaterial() returns the expected key material, with only root certs. |
| 65 | dist.Set(km2, nil) |
| 66 | if err := readAndVerifyKeyMaterial(ctx, dist, km2); err != nil { |
| 67 | t.Fatal(err) |
| 68 | } |
| 69 | |
| 70 | // Push an error into the distributor and make sure that a call to |
| 71 | // KeyMaterial() returns that error and nil keyMaterial. |
| 72 | dist.Set(km2, errProviderTestInternal) |
| 73 | if gotKM, err := dist.KeyMaterial(ctx); gotKM != nil || !errors.Is(err, errProviderTestInternal) { |
| 74 | t.Fatalf("KeyMaterial() = {%v, %v}, want {nil, %v}", gotKM, err, errProviderTestInternal) |
| 75 | } |
| 76 | |
| 77 | // Stop the distributor and KeyMaterial() should return errProviderClosed. |
| 78 | dist.Stop() |
| 79 | if km, err := dist.KeyMaterial(ctx); !errors.Is(err, errProviderClosed) { |
| 80 | t.Fatalf("KeyMaterial() = {%v, %v}, want {nil, %v}", km, err, errProviderClosed) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // TestDistributorConcurrency invokes methods on the distributor in parallel. It |
| 85 | // exercises that the scenario where a distributor's KeyMaterial() method is |
nothing calls this directly
no test coverage detected