Title: Powerful Command-Line Applications in Go: TestLoadNoFile should expect a non-nil error (page 229)

In func TestLoadNoFile , we create a temp file, delete it, and try to load it.

The test is incorrectly written to expect a nil error when we try to load the (deleted) file. It should expect an error.

cobra/pScan.v3/scan/hostsList_test.go

...
  if err := hl.Load(tf.Name()); err != nil {
    t.Errorf("Expected no error, got %q instead\n", err)
  }

Should be:

...
	if err = hl.Load(tf.Name()); err == nil {
		t.Errorf("Expected error, got nil\n")
	}
1 Like