-
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.
Merge pull request #41 from goodhosts/more-tests
adding list tests, reworked erroring to be testable
- Loading branch information
Showing
8 changed files
with
171 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() { | ||
// 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,29 @@ | ||
package cmd | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestList(t *testing.T) { | ||
args, _ := setup("-f", "no-existy", "list") | ||
err := App.Run(args) | ||
assert.NotEmpty(t, err) | ||
if runtime.GOOS == "windows" { | ||
assert.Equal(t, "open no-existy: The system cannot find the file specified.", err.Error()) | ||
} else { | ||
assert.Equal(t, "open no-existy: no such file or directory", 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