-
Notifications
You must be signed in to change notification settings - Fork 14
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
Tom
committed
Apr 23, 2020
1 parent
c39ae31
commit 57fe1ec
Showing
1 changed file
with
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package dpipes | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGopenFile(t *testing.T) { | ||
dir, _ := ioutil.TempDir("", "test") | ||
defer os.RemoveAll(dir) | ||
|
||
fname := dir + "/temp" | ||
bytes := []byte("hello world") | ||
|
||
{ | ||
stream, err := GCreate(fname) | ||
assert.Nil(t, err) | ||
stream.Write(bytes) | ||
err = stream.Close() | ||
assert.Nil(t, err) | ||
} | ||
|
||
{ | ||
stream, err := GOpen(fname) | ||
assert.Nil(t, err) | ||
data := make([]byte, 10000) | ||
n, err := stream.Read(data) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 11, n) | ||
data = data[:n] | ||
err = stream.Close() | ||
assert.Nil(t, err) | ||
assert.Equal(t, data, bytes) | ||
} | ||
} | ||
|
||
func TestGopenText(t *testing.T) { | ||
stream, err := GOpen("text:abcdef") | ||
assert.Nil(t, err) | ||
data := make([]byte, 10000) | ||
n, err := stream.Read(data) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 6, n) | ||
err = stream.Close() | ||
assert.Nil(t, err) | ||
data = data[:n] | ||
assert.Equal(t, []byte("abcdef"), data) | ||
} | ||
|
||
func TestGopenPipe(t *testing.T) { | ||
stream, err := GOpen("pipe:echo abcdef") | ||
assert.Nil(t, err) | ||
data := make([]byte, 10000) | ||
n, err := stream.Read(data) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 7, n) | ||
err = stream.Close() | ||
assert.Nil(t, err) | ||
data = data[:n] | ||
assert.Equal(t, data, []byte("abcdef\n")) | ||
} |