-
Notifications
You must be signed in to change notification settings - Fork 1
feat(connector): Databricks create — 4 auth modes with unit + e2e coverage #21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
25aa085
feat(cli): add DeclareInt helper for inheritable int flags
bradfair fa0d2ac
feat(connector): Databricks create — access-token, client-credentials…
bradfair 36fbff2
test(connector): unit-test coverage for every Databricks create leaf
bradfair 43e1f64
feat(e2e): Databricks connector live smoke coverage
bradfair 2191617
refactor(connector): hoist Databricks --client-id empty-guard to helper
bradfair bdc0c02
test(e2e): expose harness.Endpoint() and drop redundant env re-reads
bradfair 5d14d5c
test(cli): route Declare* flag-helper tests through ParseFlags
bradfair 0f50b55
test(e2e): verify create with connector get across all auth-mode leaves
bradfair 36c61ac
refactor(e2e): extract connectorCreateLeaf helper shared by Snowflake…
bradfair 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 e2e | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "regexp" | ||
| "strconv" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/highperformance-tech/ana-cli/e2e/harness" | ||
| ) | ||
|
|
||
| // connectorIDRE extracts `connectorId: <int>` from the first line of non-JSON | ||
| // stdout emitted by every `connector create <dialect> <auth-mode>` leaf. | ||
| var connectorIDRE = regexp.MustCompile(`(?m)^connectorId:\s+(\d+)\s*$`) | ||
|
|
||
| // extractConnectorID pulls the integer id out of `connectorId: <int>` stdout. | ||
| // Fails the test if no match — every create leaf's contract is to emit this | ||
| // line on success, so a miss means the output shape drifted. | ||
| func extractConnectorID(t *testing.T, stdout string) int { | ||
| t.Helper() | ||
| m := connectorIDRE.FindStringSubmatch(stdout) | ||
| if len(m) != 2 { | ||
| t.Fatalf("could not find connectorId in stdout:\n%s", stdout) | ||
| } | ||
| id, err := strconv.Atoi(m[1]) | ||
| if err != nil { | ||
| t.Fatalf("connectorId %q is not an int: %v", m[1], err) | ||
| } | ||
| return id | ||
| } | ||
|
|
||
| // connectorCreateLeaf bundles the invariants every connector-create smoke | ||
| // shares: run the command, skip post-create assertions in dry-run, extract + | ||
| // register the id, assert `connectorType: <DIALECT>`, run any leaf-specific | ||
| // stdout checks, then read the row back via `connector get` to confirm the | ||
| // server persisted the new connector. | ||
| // | ||
| // The helper exists so a parity slip (e.g., a new leaf forgetting the `get` | ||
| // round-trip) can only happen if a test intentionally bypasses this wrapper. | ||
| type connectorCreateLeaf struct { | ||
| // Name is the leaf identifier used in fatal error messages — typically | ||
| // "databricks access-token" or "snowflake oauth-sso". | ||
| Name string | ||
| // Args is the full argv passed to `h.RunStdin`, starting with | ||
| // "connector", "create", <dialect>, <auth-mode>, ... | ||
| Args []string | ||
| // Stdin is the stdin payload for secret flags (token, password, etc.). | ||
| // Empty when no --*-stdin flag is used. | ||
| Stdin string | ||
| // ConnectorType is the dialect tag asserted in stdout, e.g. "DATABRICKS" | ||
| // or "SNOWFLAKE". Matched against the literal `connectorType: <tag>` line. | ||
| ConnectorType string | ||
| // Extra runs after the common assertions and before the `connector get` | ||
| // round-trip. Use it for leaf-unique stdout fragments (OAuth endpoint | ||
| // note, per-member-lazy note, etc.). May be nil. | ||
| Extra func(stdout string) | ||
| } | ||
|
|
||
| // Run executes the leaf smoke. On non-dry-run success, the created connector | ||
| // id is registered for cleanup and read back via `connector get`. Returns the | ||
| // created id so callers can chain additional assertions if needed; in dry-run | ||
| // mode the returned id is 0. | ||
| func (l connectorCreateLeaf) Run(t *testing.T, h *harness.H) int { | ||
| t.Helper() | ||
| stdout, stderr, err := h.RunStdin(l.Stdin, l.Args...) | ||
| if err != nil { | ||
| t.Fatalf("connector create %s: %v\nstderr: %s", l.Name, err, stderr) | ||
| } | ||
| if h.DryRun() { | ||
| return 0 | ||
| } | ||
| id := extractConnectorID(t, stdout) | ||
| h.RegisterConnectorCleanup(id) | ||
| typeLine := "connectorType: " + l.ConnectorType | ||
| if !strings.Contains(stdout, typeLine) { | ||
| t.Errorf("stdout missing %s:\n%s", typeLine, stdout) | ||
| } | ||
| if l.Extra != nil { | ||
| l.Extra(stdout) | ||
| } | ||
| if _, estderr, gerr := h.Run("connector", "get", fmt.Sprint(id)); gerr != nil { | ||
| t.Fatalf("connector get %d: %v\nstderr: %s", id, gerr, estderr) | ||
| } | ||
| return id | ||
| } |
This file contains hidden or 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,161 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/highperformance-tech/ana-cli/e2e/harness" | ||
| ) | ||
|
|
||
| // dbxCommonEnv holds the Databricks workspace fields every auth mode shares. | ||
| // `port` is optional here because the CLI's --port already defaults to 443; | ||
| // only override when the env sets a non-default value. | ||
| type dbxCommonEnv struct { | ||
| host string | ||
| httpPath string | ||
| catalog string | ||
| schema string | ||
| port string | ||
| } | ||
|
|
||
| // databricksCommonEnvOrSkip reads the mode-agnostic ANA_E2E_DBX_* env vars | ||
| // and skips the calling test if any required field (HOST, HTTP_PATH, CATALOG, | ||
| // SCHEMA) is empty. Mirrors snowflakeCommonEnvOrSkip — server does up-front | ||
| // validation so submitting a made-up spec would drown the suite in noise. | ||
| func databricksCommonEnvOrSkip(t *testing.T) dbxCommonEnv { | ||
| t.Helper() | ||
| env := dbxCommonEnv{ | ||
| host: os.Getenv("ANA_E2E_DBX_HOST"), | ||
| httpPath: os.Getenv("ANA_E2E_DBX_HTTP_PATH"), | ||
| catalog: os.Getenv("ANA_E2E_DBX_CATALOG"), | ||
| schema: os.Getenv("ANA_E2E_DBX_SCHEMA"), | ||
| port: os.Getenv("ANA_E2E_DBX_PORT"), | ||
| } | ||
| if env.host == "" || env.httpPath == "" || env.catalog == "" || env.schema == "" { | ||
| t.Skip("e2e: ANA_E2E_DBX_HOST, ANA_E2E_DBX_HTTP_PATH, ANA_E2E_DBX_CATALOG, and ANA_E2E_DBX_SCHEMA must be set for Databricks tests") | ||
| } | ||
| return env | ||
| } | ||
|
|
||
| // databricksCommonArgs returns the --name/--host/--http-path/--catalog/--schema | ||
| // (+ optional --port override) flags shared by every Databricks auth-mode leaf. | ||
| func databricksCommonArgs(h *harness.H, suffix string, env dbxCommonEnv) []string { | ||
| args := []string{ | ||
| "--name", h.ResourceName(suffix), | ||
| "--host", env.host, | ||
| "--http-path", env.httpPath, | ||
| "--catalog", env.catalog, | ||
| "--schema", env.schema, | ||
| } | ||
| if env.port != "" { | ||
| args = append(args, "--port", env.port) | ||
| } | ||
| return args | ||
| } | ||
|
|
||
| // databricksLeafArgs builds the full argv for `connector create databricks | ||
| // <auth-mode>` using the shared workspace flags. `suffix` seeds the name-based | ||
| // cleanup safety-net; `extra` carries the auth-mode-specific flags. | ||
| func databricksLeafArgs(h *harness.H, authMode, suffix string, env dbxCommonEnv, extra ...string) []string { | ||
| args := append([]string{"connector", "create", "databricks", authMode}, | ||
| databricksCommonArgs(h, suffix, env)...) | ||
| return append(args, extra...) | ||
| } | ||
|
|
||
| // TestConnectorCreateDatabricksAccessToken smokes | ||
| // `connector create databricks access-token --token-stdin`. Requires | ||
| // ANA_E2E_DBX_TOKEN in addition to the common workspace env. | ||
| func TestConnectorCreateDatabricksAccessToken(t *testing.T) { | ||
| common := databricksCommonEnvOrSkip(t) | ||
| token := os.Getenv("ANA_E2E_DBX_TOKEN") | ||
| if token == "" { | ||
| t.Skip("e2e: ANA_E2E_DBX_TOKEN required for Databricks access-token mode") | ||
| } | ||
|
|
||
| h := harness.Begin(t) | ||
| h.RegisterConnectorCleanupByName(h.ResourceName("dbx-access-token")) | ||
| connectorCreateLeaf{ | ||
| Name: "databricks access-token", | ||
| Args: databricksLeafArgs(h, "access-token", "dbx-access-token", common, "--token-stdin"), | ||
| Stdin: token + "\n", | ||
| ConnectorType: "DATABRICKS", | ||
| }.Run(t, h) | ||
| } | ||
|
|
||
| // TestConnectorCreateDatabricksClientCredentials smokes the M2M leaf. | ||
| // Requires ANA_E2E_DBX_CLIENT_ID + ANA_E2E_DBX_CLIENT_SECRET (Service | ||
| // Principal applicationId + OAuth secret) alongside the workspace env. | ||
| func TestConnectorCreateDatabricksClientCredentials(t *testing.T) { | ||
| common := databricksCommonEnvOrSkip(t) | ||
| clientID := os.Getenv("ANA_E2E_DBX_CLIENT_ID") | ||
| clientSecret := os.Getenv("ANA_E2E_DBX_CLIENT_SECRET") | ||
| if clientID == "" || clientSecret == "" { | ||
| t.Skip("e2e: ANA_E2E_DBX_CLIENT_ID and ANA_E2E_DBX_CLIENT_SECRET required for Databricks client-credentials mode") | ||
| } | ||
|
|
||
| h := harness.Begin(t) | ||
| h.RegisterConnectorCleanupByName(h.ResourceName("dbx-client-credentials")) | ||
| connectorCreateLeaf{ | ||
| Name: "databricks client-credentials", | ||
| Args: databricksLeafArgs(h, "client-credentials", "dbx-client-credentials", common, "--client-id", clientID, "--client-secret-stdin"), | ||
| Stdin: clientSecret + "\n", | ||
| ConnectorType: "DATABRICKS", | ||
| }.Run(t, h) | ||
| } | ||
|
|
||
| // TestConnectorCreateDatabricksOAuthSSO smokes the oauth-sso leaf. Asserts | ||
| // the success note references the configured endpoint (matches the Snowflake | ||
| // pattern). Requires ANA_E2E_DBX_OAUTH_CLIENT_ID + | ||
| // ANA_E2E_DBX_OAUTH_CLIENT_SECRET (Databricks OAuth app credentials, distinct | ||
| // from Service Principal credentials used by client-credentials). | ||
| func TestConnectorCreateDatabricksOAuthSSO(t *testing.T) { | ||
| common := databricksCommonEnvOrSkip(t) | ||
| clientID := os.Getenv("ANA_E2E_DBX_OAUTH_CLIENT_ID") | ||
| clientSecret := os.Getenv("ANA_E2E_DBX_OAUTH_CLIENT_SECRET") | ||
| if clientID == "" || clientSecret == "" { | ||
| t.Skip("e2e: ANA_E2E_DBX_OAUTH_CLIENT_ID and ANA_E2E_DBX_OAUTH_CLIENT_SECRET required for Databricks oauth-sso mode") | ||
| } | ||
|
|
||
| h := harness.Begin(t) | ||
| h.RegisterConnectorCleanupByName(h.ResourceName("dbx-oauth-sso")) | ||
| endpoint := h.Endpoint() | ||
| connectorCreateLeaf{ | ||
| Name: "databricks oauth-sso", | ||
| Args: databricksLeafArgs(h, "oauth-sso", "dbx-oauth-sso", common, "--client-id", clientID, "--client-secret-stdin"), | ||
| Stdin: clientSecret + "\n", | ||
| ConnectorType: "DATABRICKS", | ||
| Extra: func(stdout string) { | ||
| if !strings.Contains(stdout, "complete OAuth at "+endpoint) { | ||
| t.Errorf("oauth-sso note should reference harness endpoint %q:\n%s", endpoint, stdout) | ||
| } | ||
| }, | ||
| }.Run(t, h) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // TestConnectorCreateDatabricksOAuthIndividual smokes the oauth-individual | ||
| // leaf. Asserts the per-member-lazy note since that's the only leaf-unique | ||
| // piece of stdout. Reuses the same ANA_E2E_DBX_OAUTH_CLIENT_* env pair — | ||
| // oauth-sso and oauth-individual share the same Databricks OAuth app. | ||
| func TestConnectorCreateDatabricksOAuthIndividual(t *testing.T) { | ||
| common := databricksCommonEnvOrSkip(t) | ||
| clientID := os.Getenv("ANA_E2E_DBX_OAUTH_CLIENT_ID") | ||
| clientSecret := os.Getenv("ANA_E2E_DBX_OAUTH_CLIENT_SECRET") | ||
| if clientID == "" || clientSecret == "" { | ||
| t.Skip("e2e: ANA_E2E_DBX_OAUTH_CLIENT_ID and ANA_E2E_DBX_OAUTH_CLIENT_SECRET required for Databricks oauth-individual mode") | ||
| } | ||
|
|
||
| h := harness.Begin(t) | ||
| h.RegisterConnectorCleanupByName(h.ResourceName("dbx-oauth-individual")) | ||
| connectorCreateLeaf{ | ||
| Name: "databricks oauth-individual", | ||
| Args: databricksLeafArgs(h, "oauth-individual", "dbx-oauth-individual", common, "--client-id", clientID, "--client-secret-stdin"), | ||
| Stdin: clientSecret + "\n", | ||
| ConnectorType: "DATABRICKS", | ||
| Extra: func(stdout string) { | ||
| if !strings.Contains(stdout, "lazily at first query") { | ||
| t.Errorf("oauth-individual note should mention lazy per-member auth:\n%s", stdout) | ||
| } | ||
| }, | ||
| }.Run(t, h) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.