adamwoolhether

adamwoolhether

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")
	}

Marked As Solved

rgerardi

rgerardi

Author of Powerful Command-Line Applications in Go

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

Popular Pragmatic topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
jon
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
New
belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New

Other popular topics Top

PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1127 25299 748
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New

Latest in PragProg

View all threads ❯