Skip to content

Commit 8e9e41e

Browse files
Merge branch 'development' into FE/migrations_clickhouse
2 parents 1bbe9bb + 38a6949 commit 8e9e41e

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
github.com/hamba/avro/v2 v2.18.0
3838
github.com/jlaffaye/ftp v0.2.0
3939
github.com/jmoiron/sqlx v1.3.5
40-
github.com/joho/godotenv v1.5.1
40+
github.com/joho/godotenv v1.4.0
4141
github.com/lib/pq v1.10.9
4242
github.com/mitchellh/mapstructure v1.5.0
4343
github.com/newrelic/go-agent v3.20.2+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
342342
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
343343
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
344344
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
345-
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
346-
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
345+
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
346+
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
347347
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
348348
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
349349
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=

pkg/file/azure.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package file
33
import (
44
"context"
55
"fmt"
6+
"math"
67
"math/rand"
78
"net/url"
89
"os"
@@ -62,7 +63,7 @@ func newAzureFile(c *AzureConfig, filename string, mode Mode) (*azure, error) {
6263
return nil, err
6364
}
6465

65-
azFile.parallelism = uint16(pl)
66+
azFile.parallelism = validateAndConvertToUint16(pl)
6667
}
6768

6869
return azFile, nil
@@ -100,3 +101,11 @@ func randomString() string {
100101
r := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec // Use of weak random number generator
101102
return strconv.Itoa(r.Int())
102103
}
104+
105+
func validateAndConvertToUint16(num int) uint16 {
106+
if num >= 0 && num <= math.MaxUint16 {
107+
return uint16(num)
108+
}
109+
110+
return uint16(0)
111+
}

pkg/file/azure_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/base64"
66
"errors"
7+
"math"
78
"net/url"
89
"strconv"
910
"testing"
@@ -102,6 +103,26 @@ func Test_azure_push(t *testing.T) {
102103
_ = localFile.Close()
103104
}
104105

106+
func TestValidateAndConvertToUint16(t *testing.T) {
107+
tests := []struct {
108+
desc string
109+
input int
110+
output uint16
111+
}{
112+
{"less than 0", -1, uint16(0)},
113+
{"is 0", 0, uint16(0)},
114+
{"is max uint16", math.MaxUint16, uint16(math.MaxUint16)},
115+
{"in uint16 range", 10, uint16(10)},
116+
{"greater than uint16 range", math.MaxUint16 + 1, uint16(0)},
117+
}
118+
119+
for _, tc := range tests {
120+
result := validateAndConvertToUint16(tc.input)
121+
122+
assert.Equal(t, tc.output, result)
123+
}
124+
}
125+
105126
func Test_azure_fetch(t *testing.T) {
106127
testPipelineMock := testPipeline{}
107128

0 commit comments

Comments
 (0)