File: tds_go18_test.go

package info (click to toggle)
golang-github-denisenkom-go-mssqldb 0.0~git20170717.0.8fccfc8-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports
  • size: 3,232 kB
  • sloc: makefile: 5
file content (39 lines) | stat: -rw-r--r-- 935 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package mssql

import (
	"testing"
	"net/url"
	"os"
	"fmt"
	"database/sql"
)

func TestBadConnect(t *testing.T) {
	t.Skip("still fails https://ci.appveyor.com/project/denisenkom/go-mssqldb/build/job/4jm8fmo1rywje9f9")
	var badDSNs []string

	if parsed, err := url.Parse(os.Getenv("SQLSERVER_DSN")); err == nil {
		parsed.User = url.UserPassword("baduser", "badpwd")
		badDSNs = append(badDSNs, parsed.String())
	}
	if len(os.Getenv("HOST")) > 0 && len(os.Getenv("INSTANCE")) > 0 {
		badDSNs = append(badDSNs,
			fmt.Sprintf(
				"Server=%s\\%s;User ID=baduser;Password=badpwd",
				os.Getenv("HOST"), os.Getenv("INSTANCE"),
			),
		)
	}
	SetLogger(testLogger{t})
	for _, badDsn := range badDSNs {
		conn, err := sql.Open("mssql", badDsn)
		if err != nil {
			t.Error("Open connection failed:", err.Error())
		}
		defer conn.Close()
		err = conn.Ping()
		if err == nil {
			t.Error("Ping should fail for connection: ", badDsn)
		}
	}
}