Skip to content

Commit

Permalink
Improve test code
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Apr 26, 2022
1 parent b36214e commit 7042483
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/gee/gee.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"os"
"strconv"

// "sync"

model "github.com/hahwul/gee/pkg/model"
Expand Down
60 changes: 58 additions & 2 deletions pkg/gee/gee_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gee

import (
"os"
"testing"

model "github.com/hahwul/gee/pkg/model"
Expand All @@ -15,7 +16,7 @@ func TestGee(t *testing.T) {
args args
}{
{
name: "test",
name: "test debug",
args: args{
options: model.Options{
Append: true,
Expand All @@ -25,7 +26,7 @@ func TestGee(t *testing.T) {
},
},
{
name: "test",
name: "test uniq",
args: args{
options: model.Options{
Append: true,
Expand All @@ -34,9 +35,64 @@ func TestGee(t *testing.T) {
},
},
},
{
name: "test regex",
args: args{
options: model.Options{
Append: false,
Files: []string{"", ""},
Regex: "HAHWUL",
},
},
},
{
name: "test regexv",
args: args{
options: model.Options{
Append: false,
Files: []string{"", ""},
RegexV: "HAHWUL",
},
},
},
{
name: "test chunkedLine",
args: args{
options: model.Options{
Append: false,
Files: []string{"", ""},
ChunkedLine: 1,
},
},
},
{
name: "test distribute",
args: args{
options: model.Options{
Append: false,
Files: []string{"", ""},
Distribute: true,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
input := []byte("Alice")
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}

_, err = w.Write(input)
if err != nil {
t.Error(err)
}
w.Close()
stdin := os.Stdin
// Restore stdin right after the test.
defer func() { os.Stdin = stdin }()
os.Stdin = r
Gee(tt.args.options)
})
}
Expand Down

0 comments on commit 7042483

Please sign in to comment.