]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/server_blackbox_test.go
Fix and refactor file transfers to handle resource forks
[rbdr/mobius] / hotline / server_blackbox_test.go
index 64d56ab97391341a9023e1a22ed0ecaac30cfc8b..ee5f76b04d68ec43ef08b0c46e6f5dd4444aa992 100644 (file)
@@ -66,6 +66,8 @@ func NewTestLogger() *zap.SugaredLogger {
 func StartTestServer() (*Server, context.Context, context.CancelFunc) {
        ctx, cancelRoot := context.WithCancel(context.Background())
 
 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)
        srv, err := NewServer("test/config/", "localhost", 0, NewTestLogger())
        if err != nil {
                panic(err)
@@ -82,6 +84,14 @@ func StartTestServer() (*Server, context.Context, context.CancelFunc) {
 }
 
 func TestHandshake(t *testing.T) {
 }
 
 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()
 
        srv, _, cancelFunc := StartTestServer()
        defer cancelFunc()
 
@@ -105,7 +115,7 @@ func TestHandshake(t *testing.T) {
 
 }
 
 
 }
 
-//func TestLogin(t *testing.T) {
+// func TestLogin(t *testing.T) {
 //
 //     tests := []struct {
 //             name   string
 //
 //     tests := []struct {
 //             name   string
@@ -121,13 +131,13 @@ func TestHandshake(t *testing.T) {
 //
 //             })
 //     }
 //
 //             })
 //     }
-//}
+// }
 
 func TestNewUser(t *testing.T) {
        srv, _, _ := StartTestServer()
 
        tests := []testCase{
 
 func TestNewUser(t *testing.T) {
        srv, _, _ := StartTestServer()
 
        tests := []testCase{
-               //{
+               // {
                //      name: "a valid new account",
                //      mockHandler: func() mockClientHandler {
                //              mh := mockClientHandler{}
                //      name: "a valid new account",
                //      mockHandler: func() mockClientHandler {
                //              mh := mockClientHandler{}
@@ -170,8 +180,8 @@ func TestNewUser(t *testing.T) {
                //      want: &Transaction{
                //              Fields: []Field{},
                //      },
                //      want: &Transaction{
                //              Fields: []Field{},
                //      },
-               //},
-               //{
+               // },
+               // {
                //      name: "a newUser request from a user without the required access",
                //      mockHandler: func() *mockClientHandler {
                //              mh := mockClientHandler{}
                //      name: "a newUser request from a user without the required access",
                //      mockHandler: func() *mockClientHandler {
                //              mh := mockClientHandler{}
@@ -201,8 +211,8 @@ func TestNewUser(t *testing.T) {
                //              NewField(fieldUserPassword, []byte(NegatedUserString([]byte("testPw")))),
                //              NewField(fieldUserAccess, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
                //      ),
                //              NewField(fieldUserPassword, []byte(NegatedUserString([]byte("testPw")))),
                //              NewField(fieldUserAccess, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
                //      ),
-               //},
-               //{
+               // },
+               // {
                //      name: "when user does not have required permission",
                //      mockHandler: func() map[int]*mockClientHandler {
                //              mockHandlers := make(map[int]*mockClientHandler)
                //      name: "when user does not have required permission",
                //      mockHandler: func() map[int]*mockClientHandler {
                //              mockHandlers := make(map[int]*mockClientHandler)
@@ -241,9 +251,9 @@ func TestNewUser(t *testing.T) {
                //              NewField(fieldUserPassword, []byte(NegatedUserString([]byte("testPw")))),
                //              NewField(fieldUserAccess, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
                //      ),
                //              NewField(fieldUserPassword, []byte(NegatedUserString([]byte("testPw")))),
                //              NewField(fieldUserAccess, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
                //      ),
-               //},
+               // },
 
 
-               //{
+               // {
                //      name: "a request to create a user that already exists",
                //      setup: func() {
                //
                //      name: "a request to create a user that already exists",
                //      setup: func() {
                //
@@ -269,7 +279,7 @@ func TestNewUser(t *testing.T) {
                //                      NewField(fieldError, []byte("Cannot create account guest because there is already an account with that login.")),
                //              },
                //      },
                //                      NewField(fieldError, []byte("Cannot create account guest because there is already an account with that login.")),
                //              },
                //      },
-               //},
+               // },
        }
 
        for _, test := range tests {
        }
 
        for _, test := range tests {
@@ -291,7 +301,7 @@ func TestNewUser(t *testing.T) {
                        // send test case request
                        _ = c.Send(*test.request)
 
                        // send test case request
                        _ = c.Send(*test.request)
 
-                       //time.Sleep(1 * time.Second)
+                       // time.Sleep(1 * time.Second)
                        // ===
 
                        transactions, _ := readN(c.Connection, 1)
                        // ===
 
                        transactions, _ := readN(c.Connection, 1)
@@ -310,21 +320,20 @@ func TestNewUser(t *testing.T) {
        }
 }
 
        }
 }
 
+// tranAssertEqual compares equality of transactions slices after stripping out the random ID
 func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
        var newT1 []Transaction
        var newT2 []Transaction
 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}
+       for _, trans := range tran1 {
+               trans.ID = []byte{0, 0, 0, 0}
                newT1 = append(newT1, trans)
        }
 
                newT1 = append(newT1, trans)
        }
 
-       for _, trans := range tran2{
-               trans.ID = []byte{0,0,0,0}
+       for _, trans := range tran2 {
+               trans.ID = []byte{0, 0, 0, 0}
                newT2 = append(newT2, trans)
 
        }
 
                newT2 = append(newT2, trans)
 
        }
 
-       spew.Dump(newT1, newT2)
-
        return assert.Equal(t, newT1, newT2)
        return assert.Equal(t, newT1, newT2)
-}
\ No newline at end of file
+}