Skip to content

Commit

Permalink
[chore][receiver/sqlserver] Fix newlines when testing on Windows (#32525
Browse files Browse the repository at this point in the history
)

Tests were failing on Windows because when the expected results were
loaded from a file, the newlines were `\r\n` instead of `\n`. This
replaces the unexpected characters for testing.

This is a test only change, and re-enables the tests that were being
skipped.

Resolves
#32519
  • Loading branch information
crobert-1 committed Apr 18, 2024
1 parent 6a2eae3 commit 4444bb2
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions receiver/sqlserverreceiver/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,30 @@ package sqlserverreceiver
import (
"os"
"path"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestQueryIODBWithoutInstanceName(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Test is failing on Windows, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32519")
}

expected, err := os.ReadFile(path.Join("./testdata", "databaseIOQueryWithoutInstanceName.txt"))
expectedBytes, err := os.ReadFile(path.Join("./testdata", "databaseIOQueryWithoutInstanceName.txt"))
require.NoError(t, err)
// Replace all will fix newlines when testing on Windows
expected := strings.ReplaceAll(string(expectedBytes), "\r\n", "\n")

actual := getSQLServerDatabaseIOQuery("")

require.Equal(t, string(expected), actual)
require.Equal(t, expected, actual)
}

func TestQueryIODBWithInstanceName(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Test is failing on Windows, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32519")
}

expected, err := os.ReadFile(path.Join("./testdata", "databaseIOQueryWithInstanceName.txt"))
expectedBytes, err := os.ReadFile(path.Join("./testdata", "databaseIOQueryWithInstanceName.txt"))
require.NoError(t, err)
// Replace all will fix newlines when testing on Windows
expected := strings.ReplaceAll(string(expectedBytes), "\r\n", "\n")

actual := getSQLServerDatabaseIOQuery("instanceName")

require.Equal(t, string(expected), actual)
require.Equal(t, expected, actual)
}

0 comments on commit 4444bb2

Please sign in to comment.