-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding list tests, reworked erroring to be testable
- Loading branch information
1 parent
26733a7
commit 692eb81
Showing
8 changed files
with
166 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Setup takes args slice and resets logrus and returns args to pass to App.Run | ||
func setup(args ...string) ([]string, *bytes.Buffer) { | ||
out := &bytes.Buffer{} | ||
logrus.SetOutput(out) | ||
a := os.Args[0:1] | ||
a = append(a, args...) | ||
return a, out | ||
} | ||
|
||
func read(t *testing.T, name, file string) func() { | ||
err := os.WriteFile(name, []byte(file), 0440) | ||
assert.Nil(t, err) | ||
return func() { | ||
assert.Nil(t, os.Remove(name)) | ||
} | ||
} | ||
|
||
func write(t *testing.T, name, file string) func() { | ||
Check failure on line 30 in cmd/app_test.go GitHub Actions / ci
|
||
err := os.WriteFile(name, []byte(file), 0770) | ||
assert.Nil(t, err) | ||
return func() { | ||
assert.Nil(t, os.Remove(name)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestList(t *testing.T) { | ||
args, out := setup("-f", "no-existy", "list") | ||
Check failure on line 10 in cmd/list_test.go GitHub Actions / ci
|
||
err := App.Run(args) | ||
assert.NotEmpty(t, err) | ||
assert.Equal(t, "open no-existy: The system cannot find the file specified.", err.Error()) | ||
|
||
file := "list" | ||
content := "127.0.0.1 localhost" | ||
|
||
cleanup := read(t, file, content) | ||
defer cleanup() | ||
|
||
args, out = setup("-f", file, "list") | ||
assert.Empty(t, App.Run(args)) | ||
assert.Equal(t, content+"\n", out.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters