Skip to content

Commit f4c8e76

Browse files
committed
Auto-stub host metadata endpoint in test frameworks
The host metadata resolution during config init causes test failures when mock transports don't expect the /.well-known/databricks-config call. Auto-inject a 404 response for this endpoint in qa.HTTPFixtures, client_test.go hc transport, and generated test servers. Co-authored-by: Isaac Signed-off-by: Hector Castejon Diaz <hector.castejon@databricks.com>
1 parent e215490 commit f4c8e76

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

client/client_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ import (
2222
type hc func(r *http.Request) (*http.Response, error)
2323

2424
func (cb hc) RoundTrip(r *http.Request) (*http.Response, error) {
25+
// Return 404 for host metadata endpoint to prevent config resolution
26+
// from interfering with test assertions.
27+
if r.Method == "GET" && r.URL.Path == "/.well-known/databricks-config" {
28+
return &http.Response{
29+
StatusCode: 404,
30+
Body: io.NopCloser(strings.NewReader(`{"error_code":"NOT_FOUND","message":"host metadata endpoint auto-stubbed by test framework"}`)),
31+
Request: r,
32+
}, nil
33+
}
2534
return cb(r)
2635
}
2736

internal/generatedtests/idempotency_call_test.go

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

qa/http_fixture.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,34 @@ var HTTPFailures = []HTTPFixture{
4242

4343
type HTTPFixtures []HTTPFixture
4444

45+
// hostMetadataFixture is auto-injected by the qa framework to prevent tests
46+
// from making real HTTP calls to the /.well-known/databricks-config endpoint
47+
// during config resolution. Tests that need to mock host metadata should
48+
// provide their own fixture for this endpoint.
49+
var hostMetadataFixture = HTTPFixture{
50+
Method: "GET",
51+
Resource: "/.well-known/databricks-config",
52+
ReuseRequest: true,
53+
Status: 404,
54+
Response: apierr.APIError{
55+
ErrorCode: "NOT_FOUND",
56+
StatusCode: 404,
57+
Message: "host metadata endpoint auto-stubbed by qa framework",
58+
},
59+
}
60+
61+
func (fixtures HTTPFixtures) withHostMetadata() HTTPFixtures {
62+
for _, f := range fixtures {
63+
if f.Method == "GET" && f.Resource == "/.well-known/databricks-config" {
64+
return fixtures
65+
}
66+
}
67+
return append(HTTPFixtures{hostMetadataFixture}, fixtures...)
68+
}
69+
4570
// Client creates DatabricksClient for emulated HTTP server
4671
func (fixtures HTTPFixtures) Config(t *testing.T) (*config.Config, *httptest.Server) {
72+
fixtures = fixtures.withHostMetadata()
4773
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
4874
found := false
4975
for i, fixture := range fixtures {

0 commit comments

Comments
 (0)