Skip to content

Commit 59e2032

Browse files
shueybubblesDavid Shiflet (from Dev Box)
andauthored
fix build breaks (#274)
* fix build breaks * skip azure tests --------- Co-authored-by: David Shiflet (from Dev Box) <[email protected]>
1 parent 5356bbc commit 59e2032

File tree

5 files changed

+52
-50
lines changed

5 files changed

+52
-50
lines changed

.pipelines/TestSql2017.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,9 @@ steps:
4949
workingDirectory: '$(Build.SourcesDirectory)'
5050
displayName: 'run tests'
5151
env:
52+
# skipping Azure related tests due to lack of access
5253
SQLPASSWORD: $(SQLPASSWORD)
53-
AZURESERVER_DSN: $(AZURESERVER_DSN)
5454
SQLSERVER_DSN: $(SQLSERVER_DSN)
55-
AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET)
56-
KEY_VAULT_NAME: $(KEY_VAULT_NAME)
57-
AZURE_TENANT_ID: $(AZURE_TENANT_ID)
58-
AZURE_CLIENT_ID: $(AZURE_CLIENT_ID)
59-
COLUMNENCRYPTION: 1
6055
continueOnError: true
6156
- task: PublishTestResults@2
6257
displayName: "Publish junit-style results"

bulkcopy_midnight_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,35 @@ func TestBulkCopyMidnightRounding(t *testing.T) {
1717
Size: 8, // 8 bytes for datetime
1818
},
1919
}
20-
20+
2121
// Create a Bulk instance (simplified for testing)
2222
bulk := &Bulk{}
23-
23+
2424
// Test the problematic timestamp from the issue report
2525
problematicTime := time.Date(2025, 1, 1, 23, 59, 59, 998_350_000, time.UTC)
26-
26+
2727
// Test the makeParam function directly
2828
param, err := bulk.makeParam(problematicTime, col)
2929
if err != nil {
3030
t.Fatalf("makeParam failed for problematic time: %v", err)
3131
}
32-
32+
3333
// Verify the buffer is the correct size
3434
if len(param.buffer) != 8 {
3535
t.Fatalf("Expected buffer size 8, got %d", len(param.buffer))
3636
}
37-
37+
3838
// Decode the buffer to verify it doesn't produce invalid data
39-
decoded := decodeDateTime(param.buffer)
39+
decoded := decodeDateTime(param.buffer, time.UTC)
4040
t.Logf("Original time: %s", problematicTime.Format(time.RFC3339Nano))
4141
t.Logf("Encoded/decoded time: %s", decoded.Format(time.RFC3339Nano))
42-
42+
4343
// Verify the decoded time is reasonable
4444
diff := decoded.Sub(problematicTime)
4545
if diff < 0 {
4646
diff = -diff
4747
}
48-
48+
4949
// Maximum acceptable difference for SQL Server datetime precision (1/300th of a second)
5050
maxDiff := time.Duration(3333333) // ~3.33ms in nanoseconds
5151
if diff > maxDiff {
@@ -62,9 +62,9 @@ func TestBulkCopyNearMidnightBoundaries(t *testing.T) {
6262
Size: 8,
6363
},
6464
}
65-
65+
6666
bulk := &Bulk{}
67-
67+
6868
testCases := []struct {
6969
name string
7070
time time.Time
@@ -94,32 +94,32 @@ func TestBulkCopyNearMidnightBoundaries(t *testing.T) {
9494
time: time.Date(2025, 1, 1, 23, 59, 59, 996_000_000, time.UTC),
9595
},
9696
}
97-
97+
9898
for _, tc := range testCases {
9999
t.Run(tc.name, func(t *testing.T) {
100100
param, err := bulk.makeParam(tc.time, col)
101101
if err != nil {
102102
t.Fatalf("makeParam failed: %v", err)
103103
}
104-
104+
105105
if len(param.buffer) != 8 {
106106
t.Fatalf("Expected buffer size 8, got %d", len(param.buffer))
107107
}
108-
109-
decoded := decodeDateTime(param.buffer)
108+
109+
decoded := decodeDateTime(param.buffer, time.UTC)
110110
t.Logf("Original: %s", tc.time.Format(time.RFC3339Nano))
111111
t.Logf("Decoded: %s", decoded.Format(time.RFC3339Nano))
112-
112+
113113
// Verify the decoded time is within acceptable bounds
114114
diff := decoded.Sub(tc.time)
115115
if diff < 0 {
116116
diff = -diff
117117
}
118-
118+
119119
maxDiff := time.Duration(3333333) // ~3.33ms
120120
if diff > maxDiff {
121121
t.Errorf("Time difference too large: %v > %v", diff, maxDiff)
122122
}
123123
})
124124
}
125-
}
125+
}

datetime_midnight_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,37 @@ func TestDatetimeNearMidnightBoundaries(t *testing.T) {
2121
time: time.Date(2025, 1, 1, 23, 59, 59, 997_000_000, time.UTC),
2222
},
2323
}
24-
24+
2525
for _, tc := range testCases {
2626
t.Run(tc.name, func(t *testing.T) {
2727
// Test encoding/decoding
2828
encoded := encodeDateTime(tc.time)
29-
decoded := decodeDateTime(encoded)
30-
29+
decoded := decodeDateTime(encoded, time.UTC)
30+
3131
t.Logf("Original: %s", tc.time.Format(time.RFC3339Nano))
3232
t.Logf("Decoded: %s", decoded.Format(time.RFC3339Nano))
33-
33+
3434
// Verify the decoded time is reasonable
3535
diff := decoded.Sub(tc.time)
3636
if diff < 0 {
3737
diff = -diff
3838
}
39-
39+
4040
// Maximum acceptable difference for SQL Server datetime precision
4141
maxDiff := time.Duration(3333333) // ~3.33ms in nanoseconds
4242
if diff > maxDiff {
4343
t.Errorf("Time difference too large: %v > %v", diff, maxDiff)
4444
}
45-
45+
4646
// Ensure we don't have invalid day overflow
47-
// If the original time was on Jan 1st, the decoded time should be
47+
// If the original time was on Jan 1st, the decoded time should be
4848
// either Jan 1st or Jan 2nd (if it rounded up to midnight)
4949
origDay := tc.time.Day()
5050
decodedDay := decoded.Day()
51-
51+
5252
if decodedDay != origDay && decodedDay != origDay+1 {
5353
t.Errorf("Invalid day change: original day %d, decoded day %d", origDay, decodedDay)
5454
}
5555
})
5656
}
57-
}
57+
}

encode_datetime_overflow_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
// TestEncodeDateTimeOverflow specifically tests that encodeDateTime
10-
// correctly handles day overflow when nanosToThreeHundredthsOfASecond
10+
// correctly handles day overflow when nanosToThreeHundredthsOfASecond
1111
// returns 300 (representing 1 full second).
1212
func TestEncodeDateTimeOverflow(t *testing.T) {
1313
testCases := []struct {
@@ -36,15 +36,15 @@ func TestEncodeDateTimeOverflow(t *testing.T) {
3636
expected: time.Date(2025, 1, 2, 0, 0, 0, 0, time.UTC),
3737
},
3838
}
39-
39+
4040
for _, tc := range testCases {
4141
t.Run(tc.name, func(t *testing.T) {
4242
// Encode the time
4343
encoded := encodeDateTime(tc.input)
44-
44+
4545
// Verify round-trip decoding gives the expected result
46-
decoded := decodeDateTime(encoded)
47-
46+
decoded := decodeDateTime(encoded, time.UTC)
47+
4848
if !decoded.Equal(tc.expected) {
4949
t.Errorf("Expected decoded time %v, got %v", tc.expected, decoded)
5050
}
@@ -57,13 +57,13 @@ func TestEncodeDateTimeOverflow(t *testing.T) {
5757
func TestEncodeDateTimeMaxDateOverflow(t *testing.T) {
5858
// Test time very close to end of 9999 that might overflow
5959
maxTime := time.Date(9999, 12, 31, 23, 59, 59, 998_350_000, time.UTC)
60-
60+
6161
// Encode the time
6262
encoded := encodeDateTime(maxTime)
63-
63+
6464
// Decode it back
65-
decoded := decodeDateTime(encoded)
66-
65+
decoded := decodeDateTime(encoded, time.UTC)
66+
6767
// Should be clamped to the maximum possible datetime value
6868
// SQL Server datetime max is 9999-12-31 23:59:59.997
6969
if decoded.Year() != 9999 || decoded.Month() != 12 || decoded.Day() != 31 {
@@ -76,32 +76,32 @@ func TestEncodeDateTimeMaxDateOverflow(t *testing.T) {
7676
func TestEncodeDateTimeNoOverflow(t *testing.T) {
7777
// Test case that should not trigger overflow: 997ms
7878
normalTime := time.Date(2025, 1, 1, 23, 59, 59, 997_000_000, time.UTC)
79-
79+
8080
// Encode the time
8181
encoded := encodeDateTime(normalTime)
82-
82+
8383
// Decode the days and time portions
8484
days := int32(binary.LittleEndian.Uint32(encoded[0:4]))
8585
tm := binary.LittleEndian.Uint32(encoded[4:8])
86-
86+
8787
// Calculate expected values
8888
basedays := gregorianDays(1900, 1)
8989
expectedDays := gregorianDays(2025, 1) - basedays // Should still be Jan 1st
90-
90+
9191
if days != int32(expectedDays) {
9292
t.Errorf("Expected days %d, got %d", expectedDays, days)
9393
}
94-
94+
9595
// tm should be less than a full day's worth
9696
if tm >= 300*86400 {
9797
t.Errorf("tm %d should be less than a full day (%d)", tm, 300*86400)
9898
}
99-
99+
100100
// Verify round-trip decoding
101-
decoded := decodeDateTime(encoded)
102-
101+
decoded := decodeDateTime(encoded, time.UTC)
102+
103103
// The decoded time should be on the same day (Jan 1st)
104104
if decoded.Day() != 1 || decoded.Month() != 1 || decoded.Year() != 2025 {
105105
t.Errorf("Expected decoded time to be on 2025-01-01, got %v", decoded)
106106
}
107-
}
107+
}

tds_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ func GetConnParams() (*msdsn.Config, error) {
357357
return nil, err
358358
}
359359
params.LogFlags = logFlags
360+
if os.Getenv("TIME_ZONE") != "" {
361+
tz, err := time.LoadLocation(os.Getenv("TIME_ZONE"))
362+
if err == nil {
363+
params.Encoding.Timezone = tz
364+
}
365+
}
366+
360367
return &params, nil
361368
}
362369

0 commit comments

Comments
 (0)