Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle https://xorm.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
898B

  1. // Copyright 2019 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package xorm
  5. import (
  6. "reflect"
  7. "testing"
  8. "xorm.io/core"
  9. )
  10. func TestParseMSSQL(t *testing.T) {
  11. tests := []struct {
  12. in string
  13. expected string
  14. valid bool
  15. }{
  16. {"sqlserver://sa:yourStrong(!)Password@localhost:1433?database=db&connection+timeout=30", "db", true},
  17. {"server=localhost;user id=sa;password=yourStrong(!)Password;database=db", "db", true},
  18. }
  19. driver := core.QueryDriver("mssql")
  20. for _, test := range tests {
  21. uri, err := driver.Parse("mssql", test.in)
  22. if err != nil && test.valid {
  23. t.Errorf("%q got unexpected error: %s", test.in, err)
  24. } else if err == nil && !reflect.DeepEqual(test.expected, uri.DbName) {
  25. t.Errorf("%q got: %#v want: %#v", test.in, uri.DbName, test.expected)
  26. }
  27. }
  28. }