dialect_mssql_test.go 909 B

1234567891011121314151617181920212223242526272829303132333435
  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. "github.com/go-xorm/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. }