makeTLSCreds is a test helper which creates a TLS based transport credentials from files specified in the arguments.
(t *testing.T, certPath, keyPath, rootsPath string)
| 211 | // makeTLSCreds is a test helper which creates a TLS based transport credentials |
| 212 | // from files specified in the arguments. |
| 213 | func makeTLSCreds(t *testing.T, certPath, keyPath, rootsPath string) credentials.TransportCredentials { |
| 214 | cert, err := tls.LoadX509KeyPair(testdata.Path(certPath), testdata.Path(keyPath)) |
| 215 | if err != nil { |
| 216 | t.Fatalf("tls.LoadX509KeyPair(%q, %q) failed: %v", certPath, keyPath, err) |
| 217 | } |
| 218 | b, err := os.ReadFile(testdata.Path(rootsPath)) |
| 219 | if err != nil { |
| 220 | t.Fatalf("os.ReadFile(%q) failed: %v", rootsPath, err) |
| 221 | } |
| 222 | roots := x509.NewCertPool() |
| 223 | if !roots.AppendCertsFromPEM(b) { |
| 224 | t.Fatal("failed to append certificates") |
| 225 | } |
| 226 | return credentials.NewTLS(&tls.Config{ |
| 227 | Certificates: []tls.Certificate{cert}, |
| 228 | RootCAs: roots, |
| 229 | }) |
| 230 | } |
| 231 | |
| 232 | const ( |
| 233 | wantHeaderData = "headerData" |
no test coverage detected