-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
56 additions
and
0 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,45 @@ | ||
package cli | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"sort" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestRun_Success(t *testing.T) { | ||
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer) | ||
cl := NewCLI(outStream, errStream) | ||
target := "testdata" | ||
status := cl.run(target, false, 0) | ||
if status != ExitCodeOK { | ||
t.Errorf("ExitStatus=%d, want %d", status, ExitCodeOK) | ||
} | ||
actualList := strings.Split(outStream.String(), "\n") | ||
// last element is unused | ||
actualList = actualList[:len(actualList)-1] | ||
expectedList := dirList(t, target) | ||
sort.Slice(actualList, func(i, j int) bool { return actualList[i] < actualList[j] }) | ||
|
||
if diff := cmp.Diff(actualList, expectedList); diff != "" { | ||
t.Errorf("file list mismatch (-actual +expected):\n%s", diff) | ||
} | ||
} | ||
|
||
func dirList(t *testing.T, target string) []string { | ||
files, err := os.ReadDir(target) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
names := make([]string, 0, len(files)) | ||
|
||
for _, file := range files { | ||
names = append(names, file.Name()) | ||
} | ||
|
||
return names | ||
} |
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/catatsuy/lls | ||
|
||
go 1.17 | ||
|
||
require github.com/google/go-cmp v0.5.6 |
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,4 @@ | ||
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= | ||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |