...

Package mock

import "cloud.google.com/go/cloudsqlconn/internal/mock"
Overview
Index

Overview ▾

Index ▾

func GenerateCertWithCommonName(i FakeCSQLInstance, cn string) []byte
func NewSQLAdminService(ctx context.Context, reqs ...*Request) (*sqladmin.Service, func() error, error)
func SelfSign(c *x509.Certificate, k *rsa.PrivateKey) ([]byte, error)
func SignWithClientKey(c *x509.Certificate, k *rsa.PrivateKey, clientKey *rsa.PublicKey) ([]byte, error)
func StartServerProxy(t *testing.T, i FakeCSQLInstance) func()
type ClientSignFunc
type EmptyTokenSource
    func (EmptyTokenSource) Token() (*oauth2.Token, error)
type FakeCSQLInstance
    func NewFakeCSQLInstance(project, region, name string, opts ...FakeCSQLInstanceOption) FakeCSQLInstance
    func (f FakeCSQLInstance) ClientCert(pubKey *rsa.PublicKey) ([]byte, error)
    func (f FakeCSQLInstance) String() string
type FakeCSQLInstanceOption
    func WithCertExpiry(t time.Time) FakeCSQLInstanceOption
    func WithCertSigner(s SignFunc) FakeCSQLInstanceOption
    func WithClientCertSigner(s ClientSignFunc) FakeCSQLInstanceOption
    func WithEngineVersion(s string) FakeCSQLInstanceOption
    func WithFirstGenBackend() FakeCSQLInstanceOption
    func WithNoIPAddrs() FakeCSQLInstanceOption
    func WithPSC(dns string) FakeCSQLInstanceOption
    func WithPrivateIP(addr string) FakeCSQLInstanceOption
    func WithPublicIP(addr string) FakeCSQLInstanceOption
    func WithRegion(region string) FakeCSQLInstanceOption
type Request
    func CreateEphemeral500(i FakeCSQLInstance, count int) *Request
    func CreateEphemeralSuccess(i FakeCSQLInstance, ct int) *Request
    func InstanceGet500(i FakeCSQLInstance, count int) *Request
    func InstanceGetSuccess(i FakeCSQLInstance, ct int) *Request
type SignFunc

Package files

cloudsql.go sqladmin.go

func GenerateCertWithCommonName

func GenerateCertWithCommonName(i FakeCSQLInstance, cn string) []byte

GenerateCertWithCommonName produces a certificate signed by the Fake Cloud SQL instance's CA with the specified common name cn.

func NewSQLAdminService

func NewSQLAdminService(ctx context.Context, reqs ...*Request) (*sqladmin.Service, func() error, error)

NewSQLAdminService creates a SQL Admin API service backed by a mock HTTP backend. Callers should use the cleanup function to close down the server. If the cleanup function returns an error, a caller has not exercised all the registered requests.

func SelfSign

func SelfSign(c *x509.Certificate, k *rsa.PrivateKey) ([]byte, error)

SelfSign produces a PEM encoded certificate that is self-signed.

func SignWithClientKey

func SignWithClientKey(c *x509.Certificate, k *rsa.PrivateKey, clientKey *rsa.PublicKey) ([]byte, error)

SignWithClientKey produces a PEM encoded certificate signed by the parent certificate c using the server's private key and the client's public key.

func StartServerProxy

func StartServerProxy(t *testing.T, i FakeCSQLInstance) func()

StartServerProxy starts a fake server proxy and listens on the provided port on all interfaces, configured with TLS as specified by the FakeCSQLInstance. Callers should invoke the returned function to clean up all resources.

type ClientSignFunc

ClientSignFunc is a function that produces a certificate signed using the provided certificate, using the server's private key and the client's public key. The result should be PEM-encoded.

type ClientSignFunc = func(*x509.Certificate, *rsa.PrivateKey, *rsa.PublicKey) ([]byte, error)

type EmptyTokenSource

EmptyTokenSource is an Oauth2.TokenSource that returns empty tokens.

type EmptyTokenSource struct{}

func (EmptyTokenSource) Token

func (EmptyTokenSource) Token() (*oauth2.Token, error)

Token provides an empty oauth2.Token.

type FakeCSQLInstance

FakeCSQLInstance represents settings for a specific Cloud SQL instance.

Use NewFakeCSQLInstance to instantiate.

type FakeCSQLInstance struct {
    DNSName string

    // Key is the server's private key
    Key *rsa.PrivateKey
    // Cert is the server's certificate
    Cert *x509.Certificate
    // contains filtered or unexported fields
}

func NewFakeCSQLInstance

func NewFakeCSQLInstance(project, region, name string, opts ...FakeCSQLInstanceOption) FakeCSQLInstance

NewFakeCSQLInstance returns a CloudSQLInst object for configuring mocks.

func (FakeCSQLInstance) ClientCert

func (f FakeCSQLInstance) ClientCert(pubKey *rsa.PublicKey) ([]byte, error)

ClientCert creates an ephemeral client certificate signed with the Cloud SQL instance's private key. The return value is PEM encoded.

func (FakeCSQLInstance) String

func (f FakeCSQLInstance) String() string

String returns the instance connection name for the instance.

type FakeCSQLInstanceOption

FakeCSQLInstanceOption is a function that configures a FakeCSQLInstance.

type FakeCSQLInstanceOption func(f *FakeCSQLInstance)

func WithCertExpiry

func WithCertExpiry(t time.Time) FakeCSQLInstanceOption

WithCertExpiry sets the server certificate's expiration to t.

func WithCertSigner

func WithCertSigner(s SignFunc) FakeCSQLInstanceOption

WithCertSigner configures the signing function used to generate a signed certificate.

func WithClientCertSigner

func WithClientCertSigner(s ClientSignFunc) FakeCSQLInstanceOption

WithClientCertSigner configures the signing function used to generate a certificate signed with the client's public key.

func WithEngineVersion

func WithEngineVersion(s string) FakeCSQLInstanceOption

WithEngineVersion sets the "DB Version"

func WithFirstGenBackend

func WithFirstGenBackend() FakeCSQLInstanceOption

WithFirstGenBackend sets the server backend type to FIRST_GEN.

func WithNoIPAddrs

func WithNoIPAddrs() FakeCSQLInstanceOption

WithNoIPAddrs configures a Fake Cloud SQL instance to have no IP addresses.

func WithPSC

func WithPSC(dns string) FakeCSQLInstanceOption

WithPSC sets the PSC DnsName to addr.

func WithPrivateIP

func WithPrivateIP(addr string) FakeCSQLInstanceOption

WithPrivateIP sets the private IP address to addr.

func WithPublicIP

func WithPublicIP(addr string) FakeCSQLInstanceOption

WithPublicIP sets the public IP address to addr.

func WithRegion

func WithRegion(region string) FakeCSQLInstanceOption

WithRegion sets the server's region to the provided value.

type Request

Request represents a HTTP request for a test Server to mock responses for.

Use NewRequest to initialize new Requests.

type Request struct {
    sync.Mutex
    // contains filtered or unexported fields
}

func CreateEphemeral500

func CreateEphemeral500(i FakeCSQLInstance, count int) *Request

CreateEphemeral500 returns a 500 HTTP response.

func CreateEphemeralSuccess

func CreateEphemeralSuccess(i FakeCSQLInstance, ct int) *Request

CreateEphemeralSuccess returns a Request that responds to the `connect.generateEphemeralCert` SQL Admin endpoint. It responds with a "StatusOK" and a SslCerts object.

https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/connect/generateEphemeralCert

func InstanceGet500

func InstanceGet500(i FakeCSQLInstance, count int) *Request

InstanceGet500 returns a 500 HTTP response

func InstanceGetSuccess

func InstanceGetSuccess(i FakeCSQLInstance, ct int) *Request

InstanceGetSuccess returns a Request that responds to the `instance.get` SQL Admin endpoint. It responds with a "StatusOK" and a DatabaseInstance object.

https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/instances/get

type SignFunc

SignFunc is a function that signs the certificate using the provided key. The result should be PEM-encoded.

type SignFunc = func(*x509.Certificate, *rsa.PrivateKey) ([]byte, error)