-
Notifications
You must be signed in to change notification settings - Fork 1
Support custom subject commands #53
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package config | ||
|
|
||
| import "testing" | ||
|
|
||
| // TestCloneForRunIsolatesMutatedFields pins the invariant the CLI relies on: | ||
| // each (case, subject) pair runs against its own copy, so the runner rewriting | ||
| // `${NAME}` into an endpoint command — or seeding a rotated cert into | ||
| // vault.secrets — cannot leak into the next subject's run. | ||
| func TestCloneForRunIsolatesMutatedFields(t *testing.T) { | ||
| orig := &TestCase{ | ||
| Name: "resolve-case", | ||
| Endpoints: []Endpoint{{ | ||
| Name: "device", | ||
| Command: []string{"send", "--token", "${TOKEN}"}, | ||
| Env: map[string]string{"TOKEN": "${TOKEN}"}, | ||
| }}, | ||
| Vault: &VaultConfig{Secrets: map[string]map[string]string{ | ||
| "tls": {"cert": "original"}, | ||
| }}, | ||
| } | ||
|
|
||
| cp := orig.CloneForRun() | ||
|
|
||
| // Same rewrites the runner performs, applied to the copy only. | ||
| cp.Endpoints[0].Command[2] = "subject-a-token" | ||
| cp.Endpoints[0].Env["TOKEN"] = "subject-a-token" | ||
| cp.Vault.Secrets["tls"]["cert"] = "rotated" | ||
|
|
||
| if got := orig.Endpoints[0].Command[2]; got != "${TOKEN}" { | ||
| t.Errorf("original endpoint command mutated: got %q, want %q", got, "${TOKEN}") | ||
| } | ||
| if got := orig.Endpoints[0].Env["TOKEN"]; got != "${TOKEN}" { | ||
| t.Errorf("original endpoint env mutated: got %q, want %q", got, "${TOKEN}") | ||
| } | ||
| if got := orig.Vault.Secrets["tls"]["cert"]; got != "original" { | ||
| t.Errorf("original vault secret mutated: got %q, want %q", got, "original") | ||
| } | ||
| if cp.Name != orig.Name { | ||
| t.Errorf("clone lost scalar fields: got name %q, want %q", cp.Name, orig.Name) | ||
| } | ||
| } | ||
|
|
||
| // TestCloneForRunHandlesEmptyCase covers the nil/empty shapes most cases have — | ||
| // no endpoints and no vault block — where the clone must not invent one. | ||
| func TestCloneForRunHandlesEmptyCase(t *testing.T) { | ||
| if got := (*TestCase)(nil).CloneForRun(); got != nil { | ||
| t.Fatalf("nil case cloned to %v, want nil", got) | ||
| } | ||
| cp := (&TestCase{Name: "bare"}).CloneForRun() | ||
| if cp.Endpoints != nil { | ||
| t.Errorf("endpoints became %v, want nil", cp.Endpoints) | ||
| } | ||
| if cp.Vault != nil { | ||
| t.Errorf("vault became %v, want nil", cp.Vault) | ||
| } | ||
| } |
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
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.