Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can β€” learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company πŸ‘‡

fix(khaos): the reporting flags advertised the wrong thing to take

CarterPerez-dev04a6eea1ac31
diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/cli/emit_test.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/cli/emit_test.go
index 6b3b9287..30d03e2b 100644
--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/cli/emit_test.go
+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/cli/emit_test.go
@@ -14,6 +14,7 @@ import (
"github.com/CarterPerez-dev/khaos/internal/experiment"
"github.com/CarterPerez-dev/khaos/internal/record"
+ "github.com/spf13/pflag"
)
func emitted(t *testing.T) (experiment.Result, experiment.Definition) {
@@ -397,3 +398,37 @@ func TestAProjectionThatCannotBeWrittenIsNotSilent(t *testing.T) {
t.Fatalf("a projection khaos could not write was silent: %v", err)
}
}
+
+// pflag advertises a flag's value by the FIRST backquoted word in its usage
+// string, so that placeholder is prose maintained like a signature. Three of
+// these were wrong on arrival: `--record` takes a DIRECTORY and advertised
+// `run.json`, so an operator reads the help and passes a filename; `--junit`
+// advertised `skipped`, which is a JUnit element and not a value at all; and
+// `--metrics-out` advertised nothing and fell back to `string` beside two
+// neighbours that did not.
+func TestTheReportingFlagsAdvertiseWhatTheyTake(t *testing.T) {
+ definition := outage(t)
+ sub := experimentCmdFor(t, newRunCmd(), definition)
+
+ for name, want := range map[string]string{
+ flagRecord: "dir",
+ flagJUnit: "file",
+ flagMetricsOut: "file",
+ } {
+ flag := sub.Flags().Lookup(name)
+ if flag == nil {
+ t.Fatalf("--%s is not registered on %s", name, definition.Name)
+ }
+
+ got, _ := pflag.UnquoteUsage(flag)
+ if got != want {
+ t.Errorf(
+ "--%s advertises %q, want %q: a placeholder an operator can "+
+ "mistake for a value or a default sends them to the wrong shape",
+ name,
+ got,
+ want,
+ )
+ }
+ }
+}
diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/cli/experiment.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/cli/experiment.go
index b5f1f8fb..0dc05dfd 100644
--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/cli/experiment.go
+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/cli/experiment.go
@@ -51,13 +51,13 @@ const (
outputText = "text"
outputJSON = "json"
- recordUsage = "a directory to write the canonical run record into, as `run.json` plus an `events.jsonl` beside it carrying one line per observation. The record is what every other output khaos produces is a projection of, and it is the only form that survives the terminal scrolling away"
+ recordUsage = "a `dir`ectory to write the canonical run record into, as run.json plus an `events.jsonl` beside it carrying one line per observation. The record is what every other output khaos produces is a projection of, and it is the only form that survives the terminal scrolling away"
outputUsage = "`text` for the terminal report, or `json` to write the run record to stdout and suppress every other line, so `khaos run x --output json | jq .verdict` works"
- junitUsage = "a file to write JUnit XML to, for CI test reporters. A run khaos declined to conclude from becomes a `skipped` rather than a `failure`, which is what stops thin evidence breaking a build on noise; only a control that failed in the direction this experiment declares a defect becomes a `failure`"
+ junitUsage = "a `file` to write JUnit XML to, for CI test reporters. A run khaos declined to conclude from becomes a skipped rather than a failure, which is what stops thin evidence breaking a build on noise; only a control that failed in the direction this experiment declares a defect becomes a failure"
- metricsUsage = "a file to write Prometheus text exposition to, for node_exporter's textfile collector. Written atomically and consumed by pointing that collector at the directory; khaos stands up no server and opens no port"
+ metricsUsage = "a `file` to write Prometheus text exposition to, for node_exporter's textfile collector. Written atomically and consumed by pointing that collector at the directory; khaos stands up no server and opens no port"
failOnUsage = "which outcomes keep a non-zero exit code. `any` is the default and narrows nothing, because a run khaos declined to conclude from exiting 0 is a green build on no evidence; `never` reports every measurable outcome as 0 and leaves the detail to the run record; or name the outcomes to gate on, comma separated, where `defect` alone is the shape a pipeline that should only break on a security regression wants. A rollback failure, a usage error and an internal error ignore this flag, because an unreverted fault makes every later job on that runner untrustworthy"