MCPcopy Create free account
hub / github.com/google/go-cloud / TestInstanceFromURL

Function TestInstanceFromURL

postgres/gcppostgres/gcppostgres_test.go:93–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestInstanceFromURL(t *testing.T) {
94 tests := []struct {
95 name string
96 urlString string
97 wantInstance string
98 wantDatabase string
99 wantErr bool
100 }{
101 {
102 name: "AllValuesSpecified",
103 urlString: "gcppostgres://username:password@my-project-id/us-central1/my-instance-id/my-db?foo=bar&baz=quux",
104 wantInstance: "my-project-id:us-central1:my-instance-id",
105 wantDatabase: "my-db",
106 },
107 {
108 name: "OptionalValuesOmitted",
109 urlString: "gcppostgres://my-project-id/us-central1/my-instance-id/my-db",
110 wantInstance: "my-project-id:us-central1:my-instance-id",
111 wantDatabase: "my-db",
112 },
113 {
114 name: "DatabaseNameEmpty",
115 urlString: "gcppostgres://my-project-id/us-central1/my-instance-id/",
116 wantErr: true,
117 },
118 {
119 name: "InstanceEmpty",
120 urlString: "gcppostgres://my-project-id/us-central1//my-db",
121 wantErr: true,
122 },
123 {
124 name: "RegionEmpty",
125 urlString: "gcppostgres://my-project-id//my-instance-id/my-db",
126 wantErr: true,
127 },
128 {
129 name: "ProjectEmpty",
130 urlString: "gcppostgres:///us-central1/my-instance-id/my-db",
131 wantErr: true,
132 },
133 {
134 name: "DatabaseNameWithSlashes",
135 urlString: "gcppostgres://my-project-id/us-central1/my-instance-id/foo/bar/baz",
136 wantInstance: "my-project-id:us-central1:my-instance-id",
137 wantDatabase: "foo/bar/baz",
138 },
139 }
140 for _, test := range tests {
141 t.Run(test.name, func(t *testing.T) {
142 u, err := url.Parse(test.urlString)
143 if err != nil {
144 t.Fatalf("failed to parse URL %q: %v", test.urlString, err)
145 }
146 instance, database, err := instanceFromURL(u)
147 if err != nil {
148 t.Logf("instanceFromURL(url.Parse(%q)): %v", u, err)
149 if !test.wantErr {
150 t.Fail()

Callers

nothing calls this directly

Calls 1

instanceFromURLFunction · 0.70

Tested by

no test coverage detected