Skip to content

Commit

Permalink
Added the ability to run go-datakit tests on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Ferquel <[email protected]>
  • Loading branch information
simonferquel committed Oct 6, 2016
1 parent de8158b commit 33db451
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions api/go-datakit/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To run test on windows, launch the a datakit server with --url \\.\pipe\datakit-test
15 changes: 10 additions & 5 deletions api/go-datakit/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ func TestInit(t *testing.T) {
t.Fatalf("Mkdir failed: %v", err)
}
filePath := append(path, "filename")
largeFilePath := append(path, "largefile")
var largeDataInput []byte
for ix := 0; ix < client.session.MaxReadSize()+150; ix++ {
largeDataInput = append(largeDataInput, byte(ix))
}

err = client.Remove(ctx, filePath...)
if err != nil {
t.Fatalf("Remove failed: %v", err)
Expand Down Expand Up @@ -82,6 +78,13 @@ func TestInit(t *testing.T) {
file.Close(ctx)
file.Close(ctx) // should be idempotent

t.Logf("max read size is %v", client.session.MaxReadSize())
t.Logf("max write size is %v", client.session.MaxWriteSize())
largeFilePath := append(path, "largefile")
var largeDataInput []byte
for ix := 0; ix < client.session.MaxReadSize()*2+150; ix++ {
largeDataInput = append(largeDataInput, byte(ix))
}
file, err = client.Create(ctx, largeFilePath...)
if err != nil {
t.Fatalf("Create %v failed: %v", filePath, err)
Expand All @@ -94,6 +97,7 @@ func TestInit(t *testing.T) {
if n != len(largeDataInput) {
t.Fatalf("Write was only partial: %v", err)
}
t.Logf("Written %v bytes successfully", n)
readBackData := make([]byte, len(largeDataInput)+2) // make sure reported length when ReadAll is called has the right value
n, err = io.ReadFull(file.NewIOReader(ctx, 0), readBackData)
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
Expand All @@ -105,4 +109,5 @@ func TestInit(t *testing.T) {
if bytes.Compare(largeDataInput, readBackData[:n]) != 0 {
t.Fatalf("The message we read back was different to the message we wrote")
}
t.Logf("Read %v bytes successfully", n)
}
4 changes: 0 additions & 4 deletions api/go-datakit/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"golang.org/x/net/context"
)

func dial(ctx context.Context) (*Client, error) {
return Dial(ctx, "unix", "/var/tmp/foo")
}

func TestConfig(t *testing.T) {
ctx := context.Background()
log.Println("Testing the configuration interface")
Expand Down
9 changes: 9 additions & 0 deletions api/go-datakit/dial_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build linux darwin

package datakit

import "golang.org/x/net/context"

func dial(ctx context.Context) (*Client, error) {
return Dial(ctx, "unix", "/var/tmp/foo")
}
15 changes: 15 additions & 0 deletions api/go-datakit/dial_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package datakit

import (
"context"

"github.com/Microsoft/go-winio"
)

func dial(ctx context.Context) (*Client, error) {
conn, err := winio.DialPipe(`\\.\pipe\datakit-test`, nil)
if err != nil {
return nil, err
}
return NewClient(ctx, conn)
}

0 comments on commit 33db451

Please sign in to comment.