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

**URL:** <https://forum.devtalk.com/t/title-powerful-command-line-applications-in-go-testloadnofile-should-expect-a-non-nil-error-page-229/40562>\
**Category:** PragProg Customers\
**Tags:** book-powerful-command-line-applications-in-go\
**Created:** [14 February 2022 13:47 UTC](https://forum.devtalk.com/t/title-powerful-command-line-applications-in-go-testloadnofile-should-expect-a-non-nil-error-page-229/40562 "2022-02-14T13:47:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamwoolhether](https://forum.devtalk.com/user_avatar/forum.devtalk.com/adamwoolhether/32/3877_2.png) [@adamwoolhether](https://forum.devtalk.com/u/adamwoolhether)\
**Post date:** [14 February 2022 13:47 UTC](https://forum.devtalk.com/t/title-powerful-command-line-applications-in-go-testloadnofile-should-expect-a-non-nil-error-page-229/40562/1 "2022-02-14T13:47:14Z")

</div>

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`

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

```

Should be:

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

```

---

<div class="post-metadata">

**Author:** ![rgerardi](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rgerardi/32/1035_2.png) [@rgerardi](https://forum.devtalk.com/u/rgerardi)\
**Post date:** [14 February 2022 21:29 UTC](https://forum.devtalk.com/t/title-powerful-command-line-applications-in-go-testloadnofile-should-expect-a-non-nil-error-page-229/40562/2 "2022-02-14T21:29:50Z")

</div>

Thanks @adamwoolhether . Let me check.

Ricardo

---

<div class="post-metadata">

**Author:** ![rgerardi](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rgerardi/32/1035_2.png) [@rgerardi](https://forum.devtalk.com/u/rgerardi)\
**Post date:** [15 February 2022 03:17 UTC](https://forum.devtalk.com/t/title-powerful-command-line-applications-in-go-testloadnofile-should-expect-a-non-nil-error-page-229/40562/3 "2022-02-15T03:17:16Z")

</div>

Hi @adamwoolhether , thanks for posting.

The test as shown in the book is actually correct because the method `Load` shouldn’t return an error when the file doesn’t exist. Please check the method definition a few pages before.

You can also check it by writing the test as you suggested and verifying that it fails.

The idea behind this logic is allowing the user to specify a file name in the configuration and, if it doesn’t exist, the application creates it when saving the first host.

Hope this helps.  
Ricardo

---

<div class="post-metadata">

**Author:** ![adamwoolhether](https://forum.devtalk.com/user_avatar/forum.devtalk.com/adamwoolhether/32/3877_2.png) [@adamwoolhether](https://forum.devtalk.com/u/adamwoolhether)\
**Post date:** [16 February 2022 12:32 UTC](https://forum.devtalk.com/t/title-powerful-command-line-applications-in-go-testloadnofile-should-expect-a-non-nil-error-page-229/40562/4 "2022-02-16T12:32:20Z")

</div>

Ah! You’re right. I had used our `ErrNotExists` var instead of `os.ErrNotExist` in the func `Loud()`. Sorry for that! I’ll delete this thread if i can. If not i’ll be more thoughtful moving onward.
