-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathquery_test.go
More file actions
62 lines (50 loc) · 1.75 KB
/
query_test.go
File metadata and controls
62 lines (50 loc) · 1.75 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package root
import (
"fmt"
"github.com/microsoft/go-sqlcmd/cmd/modern/root/config"
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
"os"
"runtime"
"testing"
)
// TestQuery runs a sanity test of `sqlcmd query` using the local instance on 1433
func TestQuery(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("stuartpa: This is failing in the pipeline (Login failed for user 'sa'.)")
}
cmdparser.TestSetup(t)
setupContext(t)
cmdparser.TestCmd[*Query]("PRINT")
}
func TestQueryWithNonDefaultDatabase(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("stuartpa: This is failing in the pipeline (Login failed for user 'sa'.)")
}
cmdparser.TestSetup(t)
setupContext(t)
cmdparser.TestCmd[*Query](`--text "PRINT DB_NAME()" --database master`)
// TODO: Add test validation that DB name was actually master!
}
func setupContext(t *testing.T) {
// if SQLCMDSERVER != "" add an endpoint using the --address
if os.Getenv("SQLCMDSERVER") == "" {
cmdparser.TestCmd[*config.AddEndpoint]()
} else {
t.Logf("SQLCMDSERVER: %v", os.Getenv("SQLCMDSERVER"))
cmdparser.TestCmd[*config.AddEndpoint](fmt.Sprintf("--address %v", os.Getenv("SQLCMDSERVER")))
}
// If the SQLCMDPASSWORD envvar is set, then add a basic user, otherwise
// we'll use trusted auth
if os.Getenv("SQLCMDPASSWORD") != "" &&
os.Getenv("SQLCMDUSER") != "" {
cmdparser.TestCmd[*config.AddUser](
fmt.Sprintf("--name user1 --username %s",
os.Getenv("SQLCMDUSER")))
cmdparser.TestCmd[*config.AddContext]("--endpoint endpoint --user user1")
} else {
cmdparser.TestCmd[*config.AddContext]("--endpoint endpoint")
}
cmdparser.TestCmd[*config.View]() // displaying the config (info in-case test fails)
}