Repository: snowflakedb/gosnowflake
Pull request #1417 (2025-05-20 17:33:36)

SNOW-2032700 Go driver support virtual-style domains(3)
### Description

SNOW-2032700 Please explain the changes you made here.
- [x] Removed one condition from the generate URL function. If the VirtualUrl is enabled, the bucket name should not be included even if the endPoint is specified. 

### Checklist
- [ ] Created tests which fail without the change (if possible)
- [ ] Extended the README / documentation, if necessary


sfc-gh-snowflakedb-snyk-sa: ![](https://res.cloudinary.com/snyk/image/upload/r-d/scm-platform/snyk-pull-requests/pr-banner-default.svg)

### :tada: **Snyk checks have passed. No issues have been found so far.**

:white_check_mark: **security/snyk** check is complete. No issues have been found. [(View Details)](https://app.snyk.io/org/snowflakedb-sca-scanning-public-repo/pr-checks/a3c33c34-b71b-43de-943b-13d44d3bf74b?refs=415a6cd5e8664817cfe8a4cbd1c1fb891769b3a2&source=prChecksComment)

:white_check_mark: **license/snyk** check is complete. No issues have been found. [(View Details)](https://app.snyk.io/org/snowflakedb-sca-scanning-public-repo/pr-checks/a3c33c34-b71b-43de-943b-13d44d3bf74b/license?refs=415a6cd5e8664817cfe8a4cbd1c1fb891769b3a2&source=prChecksComment)



codecov[bot]: ## [Codecov](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1417?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 82.08%. Comparing base [(`756df8c`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/756df8c12beda99a6fb6a0a71ad2603f8da7d37b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) to head [(`415a6cd`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/415a6cd5e8664817cfe8a4cbd1c1fb891769b3a2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #1417      +/-   ##
==========================================
+ Coverage   82.06%   82.08%   +0.02%     
==========================================
  Files          58       58              
  Lines       14468    14469       +1     
==========================================
+ Hits        11873    11877       +4     
+ Misses       2595     2592       -3     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1417?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).


Patch:
diff --git a/gcs_storage_client.go b/gcs_storage_client.go
index 596b665..92002b1 100644
--- a/gcs_storage_client.go
+++ b/gcs_storage_client.go
@@ -401,13 +401,15 @@ func (util *snowflakeGcsClient) generateFileURL(stageInfo *execResponseStageInfo
 	if stageInfo.EndPoint != "" {
 		endPoint = fmt.Sprintf("https://%s", stageInfo.EndPoint)
 	} else if stageInfo.UseVirtualURL {
-		bucketName := util.extractBucketNameAndPath(stageInfo.Location).bucketName
-		endPoint = fmt.Sprintf("https://%s.storage.googleapis.com", bucketName)
-		return url.Parse(endPoint + "/" + url.QueryEscape(fullFilePath))
+		endPoint = fmt.Sprintf("https://%s.storage.googleapis.com", gcsLoc.bucketName)
 	} else if stageInfo.Region != "" && isRegionalURLEnabled {
 		endPoint = fmt.Sprintf("https://storage.%s.rep.googleapis.com", strings.ToLower(stageInfo.Region))
 	}
 
+	if stageInfo.UseVirtualURL {
+		return url.Parse(endPoint + "/" + url.QueryEscape(fullFilePath))
+	}
+
 	return url.Parse(endPoint + "/" + gcsLoc.bucketName + "/" + url.QueryEscape(fullFilePath))
 }
 


Test patch:
diff --git a/gcs_storage_client_test.go b/gcs_storage_client_test.go
index bcd56c5..fcf5e29 100644
--- a/gcs_storage_client_test.go
+++ b/gcs_storage_client_test.go
@@ -1272,7 +1272,7 @@ func TestGetGcsCustomEndpoint(t *testing.T) {
 				Region:         "ME-CENTRAL2",
 				UseVirtualURL:  true,
 			},
-			expectedFileURL: "https://storage.specialEndPoint.rep.googleapis.com/my-travel-maps",
+			expectedFileURL: "https://storage.specialEndPoint.rep.googleapis.com",
 		},
 	}