MCPcopy Create free account
hub / github.com/cozystack/talm / TestRenderFailIfMultiNodes_UsesCommandName

Function TestRenderFailIfMultiNodes_UsesCommandName

pkg/engine/render_test.go:4093–4135  ·  view source on GitHub ↗

TestRenderFailIfMultiNodes_UsesCommandName guards the contract for Options.CommandName: the multi-node rejection error must reference the calling subcommand the caller passed in, never the historical hardcoded literal that pre-dated this option. An empty value falls back to the neutral "talm".

(t *testing.T)

Source from the content-addressed store, hash-verified

4091// hardcoded literal that pre-dated this option. An empty value falls back
4092// to the neutral "talm".
4093func TestRenderFailIfMultiNodes_UsesCommandName(t *testing.T) {
4094 tests := []struct {
4095 name string
4096 commandName string
4097 wantInError string
4098 }{
4099 {"talm apply", "talm apply", "talm apply"},
4100 {"talm template", "talm template", "talm template"},
4101 {"empty falls back to talm", "", "talm"},
4102 }
4103
4104 for _, tt := range tests {
4105 t.Run(tt.name, func(t *testing.T) {
4106 ctx := client.WithNodes(context.Background(), "10.0.0.1", "10.0.0.2")
4107 opts := Options{
4108 Offline: false,
4109 CommandName: tt.commandName,
4110 }
4111 _, err := Render(ctx, nil, opts)
4112 if err == nil {
4113 t.Fatalf("Render expected an error, got nil")
4114 }
4115 if !strings.Contains(err.Error(), tt.wantInError) {
4116 t.Errorf("error = %q, expected to contain %q", err.Error(), tt.wantInError)
4117 }
4118 })
4119 }
4120
4121 t.Run("non-CommandName subcommand names must not leak into the error", func(t *testing.T) {
4122 // If a caller passes "talm apply", the error must not carry any
4123 // other subcommand name — historically the call site here emitted
4124 // "talm template" unconditionally.
4125 ctx := client.WithNodes(context.Background(), "10.0.0.1", "10.0.0.2")
4126 opts := Options{Offline: false, CommandName: "talm apply"}
4127 _, err := Render(ctx, nil, opts)
4128 if err == nil {
4129 t.Fatal("Render expected an error, got nil")
4130 }
4131 if strings.Contains(err.Error(), "talm template") {
4132 t.Errorf("error must not mention 'talm template' when CommandName is 'talm apply'; got %q", err.Error())
4133 }
4134 })
4135}
4136
4137// TestRenderInvalidTalosVersion verifies that malformed TalosVersion values
4138// surface a user-friendly error before template rendering, instead of the

Callers

nothing calls this directly

Calls 2

ErrorMethod · 0.80
RenderFunction · 0.70

Tested by

no test coverage detected