forked from denisenkom/go-mssqldb
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix named pipe path handling to preserve "." (#178)
* Fix:Enable connection to WID
- Loading branch information
1 parent
80b58f2
commit ada30cb
Showing
2 changed files
with
76 additions
and
6 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
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,62 @@ | ||
package namedpipe | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/microsoft/go-mssqldb/msdsn" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseServer(t *testing.T) { | ||
c := &msdsn.Config{ | ||
Port: 1000, | ||
} | ||
n := &namedPipeDialer{} | ||
err := n.ParseServer("server", c) | ||
assert.Errorf(t, err, "ParseServer with a Port") | ||
|
||
c = &msdsn.Config{ | ||
Parameters: make(map[string]string), | ||
ProtocolParameters: make(map[string]interface{}), | ||
} | ||
err = n.ParseServer(`\\.\pipe\MSSQL$Instance\sql\query`, c) | ||
assert.NoError(t, err, "ParseServer with a full pipe name") | ||
assert.Equal(t, "", c.Host, "Config Host with a full pipe name") | ||
data, ok := c.ProtocolParameters[n.Protocol()] | ||
assert.True(t, ok, "Should have added ProtocolParameters when server is pipe name") | ||
switch d := data.(type) { | ||
case namedPipeData: | ||
assert.Equal(t, `\\.\pipe\MSSQL$Instance\sql\query`, d.PipeName, "Pipe name in ProtocolParameters when server is pipe name") | ||
default: | ||
assert.Fail(t, "Incorrect protocol parameters type:", d) | ||
} | ||
|
||
c = &msdsn.Config{ | ||
Parameters: make(map[string]string), | ||
ProtocolParameters: make(map[string]interface{}), | ||
} | ||
err = n.ParseServer(`.\instance`, c) | ||
assert.NoError(t, err, "ParseServer .") | ||
assert.Equal(t, "localhost", c.Host, `Config Host with server == .\instance`) | ||
assert.Equal(t, "instance", c.Instance, `Config Instance with server == .\instance`) | ||
_, ok = c.ProtocolParameters[n.Protocol()] | ||
assert.Equal(t, ok, false, "Should have no namedPipeData when pipe name omitted") | ||
|
||
c = &msdsn.Config{ | ||
Host: "server", | ||
Parameters: make(map[string]string), | ||
ProtocolParameters: make(map[string]interface{}), | ||
} | ||
c.Parameters["pipe"] = `myinstance\sql\query` | ||
err = n.ParseServer(`anything`, c) | ||
assert.NoError(t, err, "ParseServer anything") | ||
data, ok = c.ProtocolParameters[n.Protocol()] | ||
assert.True(t, ok, "Should have added ProtocolParameters when pipe name is provided") | ||
switch d := data.(type) { | ||
case namedPipeData: | ||
assert.Equal(t, `\\server\pipe\myinstance\sql\query`, d.PipeName, "Pipe name in ProtocolParameters") | ||
default: | ||
assert.Fail(t, "Incorrect protocol parameters type:", d) | ||
} | ||
|
||
} |