-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-921006 Introduce wiremock #1300
Open
sfc-gh-pfus
wants to merge
1
commit into
master
Choose a base branch
from
SNOW-921006-wiremock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+330
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,204 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"scenarioName": "Successful SELECT 1 flow", | ||
"request": { | ||
"urlPathPattern": "/queries/v1/query-request.*", | ||
"method": "POST", | ||
"headers": { | ||
"Authorization": { | ||
"equalTo": "%AUTHORIZATION_HEADER%" | ||
} | ||
} | ||
}, | ||
"response": { | ||
"status": 200, | ||
"jsonBody": { | ||
"data": { | ||
"parameters": [ | ||
{ | ||
"name": "TIMESTAMP_OUTPUT_FORMAT", | ||
"value": "YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM" | ||
}, | ||
{ | ||
"name": "CLIENT_PREFETCH_THREADS", | ||
"value": 4 | ||
}, | ||
{ | ||
"name": "TIME_OUTPUT_FORMAT", | ||
"value": "HH24:MI:SS" | ||
}, | ||
{ | ||
"name": "CLIENT_RESULT_CHUNK_SIZE", | ||
"value": 16 | ||
}, | ||
{ | ||
"name": "TIMESTAMP_TZ_OUTPUT_FORMAT", | ||
"value": "" | ||
}, | ||
{ | ||
"name": "CLIENT_SESSION_KEEP_ALIVE", | ||
"value": false | ||
}, | ||
{ | ||
"name": "QUERY_CONTEXT_CACHE_SIZE", | ||
"value": 5 | ||
}, | ||
{ | ||
"name": "CLIENT_METADATA_USE_SESSION_DATABASE", | ||
"value": false | ||
}, | ||
{ | ||
"name": "CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED", | ||
"value": false | ||
}, | ||
{ | ||
"name": "ENABLE_STAGE_S3_PRIVATELINK_FOR_US_EAST_1", | ||
"value": true | ||
}, | ||
{ | ||
"name": "TIMESTAMP_NTZ_OUTPUT_FORMAT", | ||
"value": "YYYY-MM-DD HH24:MI:SS.FF3" | ||
}, | ||
{ | ||
"name": "CLIENT_RESULT_PREFETCH_THREADS", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX", | ||
"value": false | ||
}, | ||
{ | ||
"name": "CLIENT_HONOR_CLIENT_TZ_FOR_TIMESTAMP_NTZ", | ||
"value": true | ||
}, | ||
{ | ||
"name": "CLIENT_MEMORY_LIMIT", | ||
"value": 1536 | ||
}, | ||
{ | ||
"name": "CLIENT_TIMESTAMP_TYPE_MAPPING", | ||
"value": "TIMESTAMP_LTZ" | ||
}, | ||
{ | ||
"name": "TIMEZONE", | ||
"value": "America/Los_Angeles" | ||
}, | ||
{ | ||
"name": "SERVICE_NAME", | ||
"value": "" | ||
}, | ||
{ | ||
"name": "CLIENT_RESULT_PREFETCH_SLOTS", | ||
"value": 2 | ||
}, | ||
{ | ||
"name": "CLIENT_TELEMETRY_ENABLED", | ||
"value": true | ||
}, | ||
{ | ||
"name": "CLIENT_DISABLE_INCIDENTS", | ||
"value": true | ||
}, | ||
{ | ||
"name": "CLIENT_USE_V1_QUERY_API", | ||
"value": true | ||
}, | ||
{ | ||
"name": "CLIENT_RESULT_COLUMN_CASE_INSENSITIVE", | ||
"value": false | ||
}, | ||
{ | ||
"name": "CSV_TIMESTAMP_FORMAT", | ||
"value": "" | ||
}, | ||
{ | ||
"name": "BINARY_OUTPUT_FORMAT", | ||
"value": "HEX" | ||
}, | ||
{ | ||
"name": "CLIENT_ENABLE_LOG_INFO_STATEMENT_PARAMETERS", | ||
"value": false | ||
}, | ||
{ | ||
"name": "CLIENT_TELEMETRY_SESSIONLESS_ENABLED", | ||
"value": true | ||
}, | ||
{ | ||
"name": "DATE_OUTPUT_FORMAT", | ||
"value": "YYYY-MM-DD" | ||
}, | ||
{ | ||
"name": "CLIENT_STAGE_ARRAY_BINDING_THRESHOLD", | ||
"value": 65280 | ||
}, | ||
{ | ||
"name": "CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY", | ||
"value": 3600 | ||
}, | ||
{ | ||
"name": "CLIENT_SESSION_CLONE", | ||
"value": false | ||
}, | ||
{ | ||
"name": "AUTOCOMMIT", | ||
"value": true | ||
}, | ||
{ | ||
"name": "TIMESTAMP_LTZ_OUTPUT_FORMAT", | ||
"value": "" | ||
} | ||
], | ||
"rowtype": [ | ||
{ | ||
"name": "1", | ||
"database": "", | ||
"schema": "", | ||
"table": "", | ||
"nullable": false, | ||
"length": null, | ||
"type": "fixed", | ||
"scale": 0, | ||
"precision": 1, | ||
"byteLength": null, | ||
"collation": null | ||
} | ||
], | ||
"rowset": [ | ||
[ | ||
"1" | ||
] | ||
], | ||
"total": 1, | ||
"returned": 1, | ||
"queryId": "01ba13b4-0104-e9fd-0000-0111029ca00e", | ||
"databaseProvider": null, | ||
"finalDatabaseName": null, | ||
"finalSchemaName": null, | ||
"finalWarehouseName": "TEST_XSMALL", | ||
"finalRoleName": "ACCOUNTADMIN", | ||
"numberOfBinds": 0, | ||
"arrayBindSupported": false, | ||
"statementTypeId": 4096, | ||
"version": 1, | ||
"sendResultTime": 1738317395581, | ||
"queryResultFormat": "json", | ||
"queryContext": { | ||
"entries": [ | ||
{ | ||
"id": 0, | ||
"timestamp": 1738317395574564, | ||
"priority": 0, | ||
"context": "CPbPTg==" | ||
} | ||
] | ||
} | ||
}, | ||
"code": null, | ||
"message": null, | ||
"success": true | ||
} | ||
} | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"scenarioName": "Successful telemetry flow", | ||
"request": { | ||
"urlPathPattern": "/telemetry/send", | ||
"method": "POST" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"jsonBody": { | ||
"data": { | ||
"code": null, | ||
"data": "Log Received", | ||
"message": null, | ||
"success": true | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package gosnowflake | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var wiremock *wiremockClient = newWiremock() | ||
|
||
type wiremockClient struct { | ||
host string | ||
port int | ||
client http.Client | ||
} | ||
|
||
func newWiremock() *wiremockClient { | ||
return &wiremockClient{ | ||
host: "127.0.0.1", | ||
port: 14355, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps it would be better to pass this as an ENV VAR in test scripsts? |
||
} | ||
} | ||
|
||
func (wm *wiremockClient) connectionConfig() *Config { | ||
return &Config{ | ||
User: "testUser", | ||
Host: wm.host, | ||
Port: wm.port, | ||
Account: "testAccount", | ||
Protocol: "http", | ||
} | ||
} | ||
|
||
type wiremockMapping struct { | ||
filePath string | ||
params map[string]string | ||
} | ||
|
||
func (wm *wiremockClient) registerMappings(t *testing.T, mappings ...wiremockMapping) { | ||
for _, mapping := range wm.enrichWithTelemetry(mappings) { | ||
f, err := os.Open("test_data/wiremock/mappings/" + mapping.filePath) | ||
assertNilF(t, err) | ||
defer f.Close() | ||
mappingBodyBytes, err := io.ReadAll(f) | ||
assertNilF(t, err) | ||
mappingBody := string(mappingBodyBytes) | ||
for key, val := range mapping.params { | ||
mappingBody = strings.Replace(mappingBody, key, val, 1) | ||
} | ||
resp, err := wm.client.Post(fmt.Sprintf("%v/import", wm.mappingsURL()), "application/json", strings.NewReader(mappingBody)) | ||
assertNilF(t, err) | ||
if resp.StatusCode != http.StatusOK { | ||
respBody, err := io.ReadAll(resp.Body) | ||
assertNilF(t, err) | ||
t.Fatalf("cannot create mapping.\n%v", string(respBody)) | ||
} | ||
} | ||
t.Cleanup(func() { | ||
req, err := http.NewRequest("DELETE", wm.mappingsURL(), nil) | ||
assertNilE(t, err) | ||
_, err = wm.client.Do(req) | ||
assertNilE(t, err) | ||
}) | ||
} | ||
|
||
func (wm *wiremockClient) enrichWithTelemetry(mappings []wiremockMapping) []wiremockMapping { | ||
return append(mappings, wiremockMapping{ | ||
filePath: "telemetry.json", | ||
}) | ||
} | ||
|
||
func (wm *wiremockClient) mappingsURL() string { | ||
return fmt.Sprintf("http://%v:%v/__admin/mappings", wm.host, wm.port) | ||
} | ||
|
||
// just to satisfy not used private variables and functions | ||
// to be removed with first real PR that uses wiremock | ||
func TestWiremock(t *testing.T) { | ||
skipOnJenkins(t, "wiremock is not enabled on Jenkins") | ||
wiremock.registerMappings(t, | ||
wiremockMapping{filePath: "select1.json"}) | ||
wiremock.connectionConfig() | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this file suggests that we are testing wiremock, but I assume that this is a base utility class for tests that use wiremock, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I have to add this suffix, because this is the only way how to exclude files from going into production.