Skip to content

Commit 2fb2f5d

Browse files
committed
PR feedback
1 parent e1d7415 commit 2fb2f5d

File tree

5 files changed

+19
-38
lines changed

5 files changed

+19
-38
lines changed

cmd/modern/root/query_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ import (
99
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
1010
"github.com/stretchr/testify/assert"
1111
"os"
12+
"runtime"
1213
"testing"
1314
)
1415

1516
// TestQuery runs a sanity test of `sqlcmd query` using the local instance on 1433
1617
func TestQuery(t *testing.T) {
17-
t.Skip("stuartpa: This is failing in the pipeline (Login failed for user 'sa'.)")
18+
if runtime.GOOS != "windows" {
19+
t.Skip("stuartpa: This is failing in the pipeline (Login failed for user 'sa'.)")
20+
}
1821
cmdparser.TestSetup(t)
1922

2023
// if SQLCMDSERVER != "" add an endpoint using the --address

internal/output/output.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,8 @@ func (o Output) InfofWithHints(hints []string, format string, a ...any) {
8282
}
8383

8484
// InfofWithHintExamples logs an info-level message with a given format and
85-
// arguments a. It also displays additional hints with example usage in the
86-
// output, using the displayHintExamples helper function. The message is
87-
// formatted using the ensureEol helper function to ensure that it ends with
88-
// a newline character. If the logging level is set to Debug, the message is prefixed
89-
// with "INFO: ". The displayHintExamples helper function formats the hints
90-
// for display and passes them to the hintCallback function for output.
85+
// arguments. It also displays additional hints with example usage in the
86+
// output.
9187
func (o Output) InfofWithHintExamples(hintExamples [][]string, format string, a ...any) {
9288
if o.loggingLevel >= verbosity.Info {
9389
format = o.ensureEol(format)

internal/secret/secret.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,15 @@ func Decode(cipherText string, decryptPassword bool) (plainText string) {
5151
}
5252

5353
// DecodeAsUtf16 takes a cipher text and a boolean indicating whether to decrypt
54-
// and returns the resulting plain text as a byte array in UTF-16LE format which
54+
// and returns the resulting plain text as a byte array in UTF-16 format which
5555
// is required when passing the secret to applications written using managed
5656
// code (C#), such as Azure Data Studio.
5757
func DecodeAsUtf16(cipherText string, decryptPassword bool) []byte {
5858
var buf bytes.Buffer
5959
secret := Decode(cipherText, decryptPassword)
6060
runes := utf16.Encode([]rune(secret))
6161

62-
const BOM = '\ufffe' //LE BOM
6362
var b [2]byte
64-
b[0] = BOM >> 8
65-
b[1] = BOM & 255
6663
for _, r := range runes {
6764
b[1] = byte(r >> 8)
6865
b[0] = byte(r & 255)

internal/tools/tool/base.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ import (
99
)
1010

1111
type Base struct {
12-
name string
13-
isInstalledCalled bool
14-
installed bool
15-
lookPathError error
16-
exeName string
17-
exeFullPath string
18-
description Description
12+
name string
13+
installed *bool
14+
lookPathError error
15+
exeName string
16+
exeFullPath string
17+
description Description
1918
}
2019

2120
func (t *Base) Init() {
@@ -51,8 +50,8 @@ func (t *Base) Where() string {
5150
}
5251

5352
func (t *Base) IsInstalled() bool {
54-
if t.isInstalledCalled {
55-
return t.installed
53+
if t.installed != nil {
54+
return *t.installed
5655
}
5756

5857
if t.exeName == "" {
@@ -62,12 +61,11 @@ func (t *Base) IsInstalled() bool {
6261
t.exeFullPath, t.lookPathError = exec.LookPath(t.exeName)
6362

6463
if t.lookPathError == nil {
65-
t.installed = true
64+
t.installed = new(bool)
65+
*t.installed = true
6666
}
6767

68-
t.isInstalledCalled = true
69-
70-
return t.installed
68+
return *t.installed
7169
}
7270

7371
func (t *Base) HowToInstall() string {
@@ -94,7 +92,7 @@ func (t *Base) HowToInstall() string {
9492
}
9593

9694
func (t *Base) Run(args []string) (int, error) {
97-
if !t.isInstalledCalled {
95+
if t.installed == nil {
9896
panic("Call IsInstalled before Run")
9997
}
10098

internal/tools/tool/base_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package tool
22

33
import (
44
"github.com/stretchr/testify/assert"
5-
"os"
65
"testing"
76
)
87

@@ -38,18 +37,6 @@ func TestIsInstalled(t *testing.T) {
3837
base := Base{}
3938
defer func() { assert.NotNil(t, recover(), "The code did not panic as expected") }()
4039
base.IsInstalled()
41-
42-
// Test when exeName is set, but LookPath returns an error
43-
base = Base{exeName: "test_exe"}
44-
base.isInstalledCalled = true
45-
base.lookPathError = os.ErrNotExist
46-
assert.True(t, base.IsInstalled())
47-
48-
// Test when exeName is set, and LookPath returns no error
49-
base = Base{exeName: "test_exe"}
50-
base.isInstalledCalled = true
51-
base.lookPathError = nil
52-
assert.False(t, base.IsInstalled())
5340
}
5441

5542
func TestHowToInstall(t *testing.T) {

0 commit comments

Comments
 (0)