mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-03 03:10:26 -05:00
integration-tests/go-sql-server-driver: Move over some more tests.
This commit is contained in:
@@ -267,7 +267,7 @@ func (s *SqlServer) DB() (*sql.DB, error) {
|
||||
authority := "root"
|
||||
location := fmt.Sprintf("tcp(127.0.0.1:%d)", s.Port)
|
||||
dbname := s.DBName
|
||||
dsn := fmt.Sprintf("%s@%s/%s?allowAllFiles=true", authority, location, dbname)
|
||||
dsn := fmt.Sprintf("%s@%s/%s?allowAllFiles=true&tls=preferred", authority, location, dbname)
|
||||
db, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -29,3 +29,7 @@ func TestCluster(t *testing.T) {
|
||||
func TestOriginal(t *testing.T) {
|
||||
RunTestsFile(t, "tests/sql-server-orig.yaml")
|
||||
}
|
||||
|
||||
func TestTLS(t *testing.T) {
|
||||
RunTestsFile(t, "tests/sql-server-tls.yaml")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIErDCCApQCCQCnSokQKR3M/zANBgkqhkiG9w0BAQUFADAYMRYwFAYDVQQKDA1E
|
||||
b2x0SHViLCBJbmMuMB4XDTIyMDcyMTIwMDgzMloXDTI2MDcxOTIwMDgzMlowGDEW
|
||||
MBQGA1UECgwNRG9sdEh1YiwgSW5jLjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCC
|
||||
AgoCggIBAMPmzHy0CmW5Xc27rbRYpJG/QKMXVAz+k2v+AkTQkUzBWKv0z8WhePB/
|
||||
tDNVfVYuYQ2sBiHTaar9nn2Lokon+YkPjyMis2aMETHVuqx0DmJb9YcxniA8M27o
|
||||
ZlfDrJtQO5UzIp9q2zhsFWj30Qdm6YUOhZ3rTnvYOMUYG/cIYLWXyQCg1oPqRVRr
|
||||
GldzLP2GdigdrS6QQjA9AdK+Zi3dP2m2vssG4gJ+lkAWOHe7wvv2RJl/alsvWXmw
|
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CEBh
|
||||
eTRSxZ7C8MhgevE47nxtyvpFmHKQzTEApYXePuz/qCAojsVh5afP3gvvPPiqQ7Qk
|
||||
vUDHm28yFm7Nwd4AsNPibzQGoJYgtA0mqKVw34YRh1yUzXXvg6MQNpUbmx+5XPQ5
|
||||
AwKCAQEA5Iye1s7RVxZP5iJ3vgy67OU+zza5yEIoJEabhF4bOBDsCwNcx2EwsQll
|
||||
X/Su5qqiIVnrRmkdYVhTnZv8bigq/8Hu+BBenMLxkAwZ5ep6gKq9wdiPQArjNBlS
|
||||
5KkGuj+7LNCsmmldXVXjjg2BNWBDdVv33hhhqsi/Tzau+qAufdNGdBTS4ZTWEH0z
|
||||
X5EBtOphJbBPeMUrm1PFOXKUDDwPfqX86rg1NHr1l5iB7uqShZak1s1ovoyFO6s7
|
||||
I9d8chi4/qwwYk8cHczB4C9EwBvWEvcAf1xa6I1Mp8y3tDhWPVIpq5P8i9vQFYIJ
|
||||
LWLCd/YowgxkNl5j6a5QMFoZvjLi5A==
|
||||
-----END PRIVATE KEY-----
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
"io"
|
||||
|
||||
"database/sql"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -102,7 +103,13 @@ type WithRemote struct {
|
||||
// |MultiRepo| before the servers are started.
|
||||
type WithFile struct {
|
||||
Name string `yaml:"name"`
|
||||
|
||||
// The contents of the file, provided inline in the YAML.
|
||||
Contents string `yaml:"contents"`
|
||||
|
||||
// A source file path to copy to |Name|. Mutually exclusive with
|
||||
// Contents.
|
||||
SourcePath string `yaml:"source_path"`
|
||||
}
|
||||
|
||||
// |Server| defines a sql-server process to start. |Name| must match the
|
||||
@@ -156,12 +163,13 @@ type Query struct {
|
||||
RetryAttempts int `yaml:"retry_attempts"`
|
||||
}
|
||||
|
||||
// |QueryResult| specifies assertions on the results of a |Query|. This must be
|
||||
// specified for a |Query| and the query results must fully match. All
|
||||
// assertions here are string equality.
|
||||
// |QueryResult| specifies assertions on the results of a |Query|. Columns must
|
||||
// be specified for a |Query| and the query results must fully match. If Rows
|
||||
// are ommited, anything is allowed as long as all rows are read successfully.
|
||||
// All assertions here are string equality.
|
||||
type QueryResult struct {
|
||||
Columns []string `yaml:"columns"`
|
||||
Rows [][]string `yaml:"rows"`
|
||||
Columns []string `yaml:"columns"`
|
||||
Rows *[][]string `yaml:"rows"`
|
||||
}
|
||||
|
||||
func ParseTestsFile(path string) (TestDef, error) {
|
||||
@@ -181,7 +189,21 @@ func (f WithFile) WriteAtDir(dir string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, []byte(f.Contents), 0550)
|
||||
if f.SourcePath != "" {
|
||||
source, err := os.Open(f.SourcePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer source.Close()
|
||||
dest, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0550)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = io.Copy(dest, source)
|
||||
return err
|
||||
} else {
|
||||
return os.WriteFile(path, []byte(f.Contents), 0550)
|
||||
}
|
||||
}
|
||||
|
||||
func MakeRepo(t *testing.T, rs RepoStore, r TestRepo) Repo {
|
||||
@@ -384,7 +406,9 @@ func RunQueryAttempt(t require.TestingT, conn *sql.Conn, q Query) {
|
||||
|
||||
rowstrings, err := RowsToStrings(len(cols), rows)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, q.Result.Rows, rowstrings)
|
||||
if q.Result.Rows != nil {
|
||||
require.Equal(t, *q.Result.Rows, rowstrings)
|
||||
}
|
||||
} else if q.Exec != "" {
|
||||
_, err := conn.ExecContext(context.Background(), q.Exec, args...)
|
||||
if q.ErrorMatch == "" {
|
||||
|
||||
@@ -289,3 +289,23 @@ tests:
|
||||
result:
|
||||
columns: ["Tables_in_repo1/feature-branch"]
|
||||
rows: [["test"]]
|
||||
- name: auto increment for a table should reset between drops
|
||||
repos:
|
||||
- name: repo1
|
||||
server: {}
|
||||
connections:
|
||||
- on: repo1
|
||||
queries:
|
||||
- exec: "CREATE TABLE t1(pk int auto_increment primary key, val int)"
|
||||
- exec: "INSERT INTO t1 VALUES (0, 1),(0, 2)"
|
||||
- query: "SELECT * FROM t1"
|
||||
result:
|
||||
columns: ["pk", "val"]
|
||||
rows: [["1", "1"], ["2", "2"]]
|
||||
- exec: "DROP TABLE t1"
|
||||
- exec: "CREATE TABLE t1(pk int auto_increment primary key, val int)"
|
||||
- exec: "INSERT INTO t1 VALUES (0, 1),(0, 2)"
|
||||
- query: "SELECT * FROM t1"
|
||||
result:
|
||||
columns: ["pk", "val"]
|
||||
rows: [["1", "1"], ["2", "2"]]
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
tests:
|
||||
- name: require_secure_transport no key or cert
|
||||
repos:
|
||||
- name: repo1
|
||||
with_files:
|
||||
- name: server.yaml
|
||||
contents: |
|
||||
listener:
|
||||
require_secure_transport: true
|
||||
server:
|
||||
args: ["--config", "server.yaml"]
|
||||
error_matches:
|
||||
- "require_secure_transport can only be `true` when a tls_key and tls_cert are provided."
|
||||
- name: tls_key non-existant
|
||||
repos:
|
||||
- name: repo1
|
||||
with_files:
|
||||
- name: chain_key.pem
|
||||
source_path: testdata/chain_key.pem
|
||||
- name: chain_cert.pem
|
||||
source_path: testdata/chain_cert.pem
|
||||
- name: server.yaml
|
||||
contents: |
|
||||
listener:
|
||||
tls_key: doesnotexist_key.pem
|
||||
tls_cert: chain_cert.pem
|
||||
server:
|
||||
args: ["--config", "server.yaml"]
|
||||
error_matches:
|
||||
- "no such file or directory"
|
||||
- name: tls_cert non-existant
|
||||
repos:
|
||||
- name: repo1
|
||||
with_files:
|
||||
- name: chain_key.pem
|
||||
source_path: testdata/chain_key.pem
|
||||
- name: chain_cert.pem
|
||||
source_path: testdata/chain_cert.pem
|
||||
- name: server.yaml
|
||||
contents: |
|
||||
listener:
|
||||
tls_key: chain_key.pem
|
||||
tls_cert: doesnotexist_key.pem
|
||||
server:
|
||||
args: ["--config", "server.yaml"]
|
||||
error_matches:
|
||||
- "no such file or directory"
|
||||
|
||||
# XXX: It would be nice to assert on the TLS use here using show status or something.
|
||||
# It would be nice to assert on failing to connect using tls=no.
|
||||
- name: tls only server
|
||||
repos:
|
||||
- name: repo1
|
||||
with_files:
|
||||
- name: chain_key.pem
|
||||
source_path: testdata/chain_key.pem
|
||||
- name: chain_cert.pem
|
||||
source_path: testdata/chain_cert.pem
|
||||
- name: server.yaml
|
||||
contents: |
|
||||
listener:
|
||||
tls_key: chain_key.pem
|
||||
tls_cert: chain_cert.pem
|
||||
require_secure_transport: true
|
||||
server:
|
||||
args: ["--config", "server.yaml"]
|
||||
connections:
|
||||
- on: repo1
|
||||
queries:
|
||||
- query: "show tables"
|
||||
result:
|
||||
columns: ["Tables_in_repo1"]
|
||||
rows: []
|
||||
Reference in New Issue
Block a user