MCPcopy
hub / github.com/hashicorp/packer / TestInitCmd

Function TestInitCmd

command/init_test.go:314–363  ·  view source on GitHub ↗

TestInitCmd aims to test the init command, with output validation

(t *testing.T)

Source from the content-addressed store, hash-verified

312
313// TestInitCmd aims to test the init command, with output validation
314func TestInitCmd(t *testing.T) {
315 tests := []struct {
316 name string
317 args []string
318 expectedCode int
319 outputCheck func(string, string) error
320 }{
321 {
322 name: "Ensure init warns on template without required_plugin blocks",
323 args: []string{
324 testFixture("hcl", "build-var-in-pp.pkr.hcl"),
325 },
326 expectedCode: 0,
327 outputCheck: func(stdout, stderr string) error {
328 if !strings.Contains(stdout, "No plugins requirement found") {
329 return fmt.Errorf("command should warn about plugin requirements not found, but did not")
330 }
331 return nil
332 },
333 },
334 }
335
336 for _, tt := range tests {
337 t.Run(tt.name, func(t *testing.T) {
338 c := &InitCommand{
339 Meta: TestMetaFile(t),
340 }
341
342 exitCode := c.Run(tt.args)
343 if exitCode != tt.expectedCode {
344 t.Errorf("process exit code mismatch: expected %d, got %d",
345 tt.expectedCode,
346 exitCode)
347 }
348
349 out, stderr := GetStdoutAndErrFromTestMeta(t, c.Meta)
350 err := tt.outputCheck(out, stderr)
351 if err != nil {
352 if len(out) != 0 {
353 t.Logf("command stdout: %q", out)
354 }
355
356 if len(stderr) != 0 {
357 t.Logf("command stderr: %q", stderr)
358 }
359 t.Error(err.Error())
360 }
361 })
362 }
363}

Callers

nothing calls this directly

Calls 7

RunMethod · 0.95
testFixtureFunction · 0.85
TestMetaFileFunction · 0.85
ErrorMethod · 0.65
ErrorfMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…