-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ParseVcapServices stops searching after the first service offering
The for loop on L103 was written to return after the checking the first entry in vcapMap, regardless of whether findMySQLTag found a suitable service or returned an error. If services from multiple service offerings are bound to the application and the service tagged with "mysql" is not in the first offering, the function will not find it. The new test case fails when run against the unmodified code. To fix this, flatten the map[string][]VcapService into a []VCapService, and pass the flat slice to findMySQLTag.
- Loading branch information
1 parent
f95bde1
commit 3c32520
Showing
2 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,6 +224,79 @@ var _ = Describe("VCAP", func() { | |
`) | ||
Expect(err).To(MatchError("error finding MySQL tag: the variable VCAP_SERVICES must have one VCAP service with a tag of 'mysql'. There are currently 0 VCAP services with the tag 'mysql'")) | ||
}) | ||
|
||
It("succeeds when VCAP_SERVICES has multiple lists but only one with a MySQL tag", func() { | ||
_, err := ParseVcapServices(`{ | ||
"google-cloudsql-mysql": [ | ||
{ | ||
"binding_name": "testbinding", | ||
"instance_name": "testinstance", | ||
"name": "kf-binding-tt2-mystorage", | ||
"label": "google-storage", | ||
"tags": [ | ||
"gcp", | ||
"cloudsql" | ||
], | ||
"plan": "nearline", | ||
"credentials": { | ||
"CaCert": "-truncated-", | ||
"ClientCert": "-truncated-", | ||
"ClientKey": "-truncated-", | ||
"Email": "[email protected]", | ||
"Name": "pcf-binding-testbind", | ||
"Password": "PASSWORD", | ||
"PrivateKeyData": "PRIVATEKEY", | ||
"ProjectId": "test-gsb", | ||
"Sha1Fingerprint": "aa3bade266136f733642ebdb4992b89eb05f83c4", | ||
"UniqueId": "108868434450972082663", | ||
"UriPrefix": "", | ||
"Username": "newuseraccount", | ||
"database_name": "service_broker", | ||
"host": "127.0.0.1", | ||
"instance_name": "pcf-sb-1-1561406852899716453", | ||
"last_master_operation_id": "", | ||
"region": "", | ||
"uri": "mysql://newuseraccount:[email protected]/service_broker?ssl_mode=required" | ||
} | ||
} | ||
], | ||
"user-provided": [ | ||
{ | ||
"binding_name": "testbinding", | ||
"instance_name": "testinstance", | ||
"name": "kf-binding-tt2-mystorage", | ||
"label": "google-storage", | ||
"tags": [ | ||
"gcp", | ||
"cloudsql", | ||
"mysql" | ||
], | ||
"plan": "nearline", | ||
"credentials": { | ||
"CaCert": "-truncated-", | ||
"ClientCert": "-truncated-", | ||
"ClientKey": "-truncated-", | ||
"Email": "[email protected]", | ||
"Name": "pcf-binding-testbind", | ||
"Password": "PASSWORD", | ||
"PrivateKeyData": "PRIVATEKEY", | ||
"ProjectId": "test-gsb", | ||
"Sha1Fingerprint": "aa3bade266136f733642ebdb4992b89eb05f83c4", | ||
"UniqueId": "108868434450972082663", | ||
"UriPrefix": "", | ||
"Username": "newuseraccount", | ||
"database_name": "service_broker", | ||
"host": "127.0.0.1", | ||
"instance_name": "pcf-sb-1-1561406852899716453", | ||
"last_master_operation_id": "", | ||
"region": "", | ||
"uri": "mysql://newuseraccount:[email protected]/service_broker?ssl_mode=required" | ||
} | ||
} | ||
] | ||
}`) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Describe("setting database credentials", func() { | ||
|