Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
weiguoz authored Jun 17, 2019
1 parent efd6636 commit 34cb362
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

var (
// Regexp syntax: https://github.com/google/re2/wiki/Syntax
reDSN = regexp.MustCompile(`^([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)@([a-zA-Z0-9/_.-]+)\?([^/]+)$`)
reDSN = regexp.MustCompile(`^([a-zA-Z0-9_-]+):([=a-zA-Z0-9_-]+)@([:a-zA-Z0-9/_.-]+)\?([^/]+)$`)
reQuery = regexp.MustCompile(`^([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)$`)
)

Expand Down
19 changes: 14 additions & 5 deletions dsn_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gomaxcompute

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestConfig_ParseDSN(t *testing.T) {
Expand Down Expand Up @@ -32,15 +33,23 @@ func TestConfig_ParseDSN(t *testing.T) {
_, err = ParseDSN(dsn)
a.Error(err)
}

goodDSN := []string{
"64pxmm:oRdhg=@127.0.0.1:8002/api?curr_project=test_ci&scheme=http",
}
for _, dsn := range goodDSN {
_, err = ParseDSN(dsn)
a.NoError(err)
}
}

func TestConfig_FormatDSN(t *testing.T) {
a := assert.New(t)
config := Config{
AccessID: "access_id",
AccessID: "access_id",
AccessKey: "access_key",
Project: "test_ci",
Endpoint: "http://service.com/api"}
Project: "test_ci",
Endpoint: "http://service.com/api"}
a.Equal("access_id:access_key@service.com/api?curr_project=test_ci&scheme=http", config.FormatDSN())
}

Expand All @@ -51,4 +60,4 @@ func TestConfig_ParseAndFormatRoundTrip(t *testing.T) {
config, err := ParseDSN(dsn)
a.NoError(err)
a.Equal(dsn, config.FormatDSN())
}
}

0 comments on commit 34cb362

Please sign in to comment.