diff options
Diffstat (limited to 'tests/test_helpers/helpers.go')
-rw-r--r-- | tests/test_helpers/helpers.go | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go index 1fe0c19..b612de0 100644 --- a/tests/test_helpers/helpers.go +++ b/tests/test_helpers/helpers.go @@ -4,17 +4,14 @@ import ( "bytes" "crypto/md5" "encoding/hex" - "encoding/json" "fmt" "io/ioutil" "log" - "net" "os" "os/exec" "path/filepath" "syscall" "testing" - "time" "github.com/rfjakob/gocryptfs/ctlsock" "github.com/rfjakob/gocryptfs/internal/nametransform" @@ -347,29 +344,24 @@ func Du(t *testing.T, fd int) (nBytes int64) { // QueryCtlSock sends a request to the control socket at "socketPath" and // returns the response. -func QueryCtlSock(t *testing.T, socketPath string, req ctlsock.RequestStruct) (response ctlsock.ResponseStruct) { - conn, err := net.DialTimeout("unix", socketPath, 1*time.Second) +func QueryCtlSock(t *testing.T, socketPath string, req ctlsock.RequestStruct) ctlsock.ResponseStruct { + c, err := ctlsock.New(socketPath) if err != nil { + // Connecting to the socket failed already. This is fatal. t.Fatal(err) } - defer conn.Close() - conn.SetDeadline(time.Now().Add(time.Second)) - msg, err := json.Marshal(req) - if err != nil { - t.Fatal(err) - } - _, err = conn.Write(msg) - if err != nil { - t.Fatal(err) - } - buf := make([]byte, 5000) - n, err := conn.Read(buf) + defer c.Close() + resp, err := c.Query(&req) if err != nil { + // If we got a response, try to extract it. This is not fatal here + // as the tests may expect error responses. + if resp2, ok := err.(*ctlsock.ResponseStruct); ok { + return *resp2 + } + // Another error means that we did not even get a response. This is fatal. t.Fatal(err) } - buf = buf[:n] - json.Unmarshal(buf, &response) - return response + return *resp } // ExtractCmdExitCode extracts the exit code from an error value that was |