Move testdata/ to internal/

This commit is contained in:
Lucas Clemente
2017-08-03 18:46:34 +02:00
parent d0fde2b230
commit 8ec11c0b53
9 changed files with 10 additions and 10 deletions

44
internal/testdata/cert.go vendored Normal file
View File

@@ -0,0 +1,44 @@
package testdata
import (
"crypto/tls"
"path"
"runtime"
)
var certPath string
func init() {
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("Failed to get current frame")
}
certPath = path.Join(path.Dir(path.Dir(path.Dir(filename))), "example")
}
// GetCertificatePaths returns the paths to 'fullchain.pem' and 'privkey.pem' for the
// quic.clemente.io cert.
func GetCertificatePaths() (string, string) {
return path.Join(certPath, "fullchain.pem"), path.Join(certPath, "privkey.pem")
}
// GetTLSConfig returns a tls config for quic.clemente.io
func GetTLSConfig() *tls.Config {
cert, err := tls.LoadX509KeyPair(GetCertificatePaths())
if err != nil {
panic(err)
}
return &tls.Config{
Certificates: []tls.Certificate{cert},
}
}
// GetCertificate returns a certificate for quic.clemente.io
func GetCertificate() tls.Certificate {
cert, err := tls.LoadX509KeyPair(GetCertificatePaths())
if err != nil {
panic(err)
}
return cert
}