MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / TestCheckConnections

Function TestCheckConnections

internal/proxy/proxy_test.go:762–813  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

760}
761
762func TestCheckConnections(t *testing.T) {
763 in := &proxy.Config{
764 Addr: "127.0.0.1",
765 Port: 24016,
766 Instances: []proxy.InstanceConnConfig{
767 {Name: "proj:region:pg"},
768 },
769 }
770 d := &fakeDialer{}
771 c, err := proxy.NewClient(context.Background(), d, testLogger, in, nil)
772 if err != nil {
773 t.Fatalf("proxy.NewClient error: %v", err)
774 }
775 defer c.Close()
776 go c.Serve(context.Background(), func() {})
777
778 n, err := c.CheckConnections(context.Background())
779 if err != nil {
780 t.Fatalf("CheckConnections failed: %v", err)
781 }
782 if want, got := len(in.Instances), n; want != got {
783 t.Fatalf("CheckConnections number of connections: want = %v, got = %v", want, got)
784 }
785
786 if want, got := 1, d.dialAttempts(); want != got {
787 t.Fatalf("dial attempts: want = %v, got = %v", want, got)
788 }
789
790 in = &proxy.Config{
791 Addr: "127.0.0.1",
792 Port: 26002,
793 Instances: []proxy.InstanceConnConfig{
794 {Name: "proj:region:pg1"},
795 {Name: "proj:region:pg2"},
796 },
797 }
798 ed := &errorDialer{}
799 c, err = proxy.NewClient(context.Background(), ed, testLogger, in, nil)
800 if err != nil {
801 t.Fatalf("proxy.NewClient error: %v", err)
802 }
803 defer c.Close()
804 go c.Serve(context.Background(), func() {})
805
806 n, err = c.CheckConnections(context.Background())
807 if err == nil {
808 t.Fatal("CheckConnections should have failed, but did not")
809 }
810 if want, got := len(in.Instances), n; want != got {
811 t.Fatalf("CheckConnections number of connections: want = %v, got = %v", want, got)
812 }
813}
814
815func TestRunConnectionCheck(t *testing.T) {
816 in := &proxy.Config{

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
ServeMethod · 0.95
CheckConnectionsMethod · 0.95
dialAttemptsMethod · 0.95
NewClientFunction · 0.92

Tested by

no test coverage detected