]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/server_blackbox_test.go
minor: v0.1.0
[rbdr/mobius] / hotline / server_blackbox_test.go
index 41d331b34c13ccd70eb6dcc2293e9cc5423ab9e2..601d745e40a215a15c8ea99567b07d0ea6f0ddb4 100644 (file)
@@ -4,11 +4,12 @@ import (
        "bytes"
        "context"
        "fmt"
+       "github.com/davecgh/go-spew/spew"
+       "github.com/stretchr/testify/assert"
        "go.uber.org/zap"
        "go.uber.org/zap/zapcore"
        "net"
        "os"
-       "reflect"
        "testing"
 )
 
@@ -65,6 +66,8 @@ func NewTestLogger() *zap.SugaredLogger {
 func StartTestServer() (*Server, context.Context, context.CancelFunc) {
        ctx, cancelRoot := context.WithCancel(context.Background())
 
+       FS = OSFileStore{}
+
        srv, err := NewServer("test/config/", "localhost", 0, NewTestLogger())
        if err != nil {
                panic(err)
@@ -81,6 +84,14 @@ func StartTestServer() (*Server, context.Context, context.CancelFunc) {
 }
 
 func TestHandshake(t *testing.T) {
+       mfs := MockFileStore{}
+       fh, _ := os.Open("./test/config/Agreement.txt")
+       mfs.On("Open", "/test/config/Agreement.txt").Return(fh, nil)
+       fh, _ = os.Open("./test/config/config.yaml")
+       mfs.On("Open", "/test/config/config.yaml").Return(fh, nil)
+       FS = mfs
+       spew.Dump(mfs)
+
        srv, _, cancelFunc := StartTestServer()
        defer cancelFunc()
 
@@ -122,7 +133,6 @@ func TestHandshake(t *testing.T) {
 //     }
 //}
 
-
 func TestNewUser(t *testing.T) {
        srv, _, _ := StartTestServer()
 
@@ -310,24 +320,19 @@ func TestNewUser(t *testing.T) {
        }
 }
 
+func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
+       var newT1 []Transaction
+       var newT2 []Transaction
+       for _, trans := range tran1 {
+               trans.ID = []byte{0, 0, 0, 0}
+               newT1 = append(newT1, trans)
+       }
 
+       for _, trans := range tran2 {
+               trans.ID = []byte{0, 0, 0, 0}
+               newT2 = append(newT2, trans)
 
-// equal is a utility function used only in tests that determines if transactions are equal enough
-func (t Transaction) equal(otherT Transaction) bool {
-       t.ID = []byte{0, 0, 0, 0}
-       otherT.ID = []byte{0, 0, 0, 0}
-
-       t.TotalSize = []byte{0, 0, 0, 0}
-       otherT.TotalSize = []byte{0, 0, 0, 0}
-
-       t.DataSize = []byte{0, 0, 0, 0}
-       otherT.DataSize = []byte{0, 0, 0, 0}
-
-       t.ParamCount = []byte{0, 0}
-       otherT.ParamCount = []byte{0, 0}
-
-       //spew.Dump(t)
-       //spew.Dump(otherT)
+       }
 
-       return reflect.DeepEqual(t, otherT)
+       return assert.Equal(t, newT1, newT2)
 }