Skip to content

Commit 5723cf1

Browse files
authored
slicetools.Batch (#35)
* slicetools/Batch * lint
1 parent 8a56a7a commit 5723cf1

File tree

15 files changed

+217
-17
lines changed

15 files changed

+217
-17
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ jobs:
3434
- name: golangci-lint
3535
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
3636
with:
37-
version: v2.1
37+
version: v2.4
3838
args: --issues-exit-code=1 --timeout 10m
3939
only-new-issues: false

.golangci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ linters:
1111
- inamedparam # reports interfaces with unnamed method parameters
1212
- wrapcheck # Checks that errors returned from external packages are wrapped
1313
- err113 # Go linter to check the errors handling expressions
14-
#- noinlineerr
14+
- noinlineerr
1515
- paralleltest # Detects missing usage of t.Parallel() method in your Go test
1616
- testpackage # linter that makes you use a separate _test package
1717
- exhaustruct # Checks if all structure fields are initialized
@@ -104,15 +104,15 @@ linters:
104104
- 43
105105
- name: defer
106106
disabled: true
107-
#- name: enforce-switch-style
108-
# disabled: true
107+
- name: enforce-switch-style
108+
disabled: true
109109
- name: flag-parameter
110110
disabled: true
111111
- name: function-length
112112
arguments:
113113
# lower this after refactoring
114114
- 104
115-
- 196
115+
- 198
116116
- name: line-length-limit
117117
arguments:
118118
# lower this after refactoring

cstest/aws.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"strings"
77
"testing"
8+
"time"
89
)
910

1011
// SetAWSTestEnv sets the environment variables required to run tests against LocalStack,
@@ -30,7 +31,9 @@ func SetAWSTestEnv(t *testing.T) string {
3031
t.Setenv("AWS_ACCESS_KEY_ID", "test")
3132
t.Setenv("AWS_SECRET_ACCESS_KEY", "test")
3233

33-
_, err := net.Dial("tcp", strings.TrimPrefix(endpoint, "http://"))
34+
dialer := &net.Dialer{Timeout: 2 * time.Second}
35+
36+
_, err := dialer.DialContext(t.Context(), "tcp", strings.TrimPrefix(endpoint, "http://"))
3437
if err != nil {
3538
t.Fatalf("%s: make sure localstack is running and retry", err)
3639
}

cstime/cstime.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"time"
99
)
1010

11-
// ParseDuration parses a string representing a duration, and supports
11+
// ParseDurationWithDays parses a string representing a duration, and supports
1212
// days as a unit (e.g., "2d", "2d3h", "24h", "2h45m").
1313
func ParseDurationWithDays(input string) (time.Duration, error) {
1414
var total time.Duration
@@ -55,6 +55,7 @@ func ParseDurationWithDays(input string) (time.Duration, error) {
5555
if err != nil {
5656
return 0, err
5757
}
58+
5859
total += dur
5960
}
6061

cstime/duration.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ type DurationWithDays time.Duration
2020
// UnmarshalText implements encoding.TextUnmarshaler (used by YAML/JSON libs).
2121
func (d *DurationWithDays) UnmarshalText(text []byte) error {
2222
s := string(text)
23+
2324
dur, err := ParseDurationWithDays(s)
2425
if err != nil {
2526
return err
2627
}
28+
2729
*d = DurationWithDays(dur)
30+
2831
return nil
2932
}
3033

@@ -39,6 +42,7 @@ func (d *DurationWithDays) UnmarshalJSON(b []byte) error {
3942
if err := json.Unmarshal(b, &s); err != nil {
4043
return err
4144
}
45+
4246
return d.UnmarshalText([]byte(s))
4347
}
4448

@@ -48,6 +52,7 @@ func (d DurationWithDays) MarshalJSON() ([]byte, error) {
4852
if err != nil {
4953
return nil, err
5054
}
55+
5156
return json.Marshal(string(s))
5257
}
5358

cstime/duration_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ func TestUnmarshalText(t *testing.T) {
5959
for _, tc := range tests {
6060
t.Run(tc.name, func(t *testing.T) {
6161
var d DurationWithDays
62+
6263
err := d.UnmarshalText([]byte(tc.input))
6364
cstest.RequireErrorContains(t, err, tc.wantErr)
65+
6466
if tc.wantErr != "" {
6567
return
6668
}
69+
6770
assert.Equal(t, tc.want, time.Duration(d))
6871
})
6972
}
@@ -115,6 +118,7 @@ func TestDuration_UnmarshalJSON(t *testing.T) {
115118
jsonInput := `{"timeout": "2d3h45m"}`
116119

117120
var cfg Config
121+
118122
err := json.Unmarshal([]byte(jsonInput), &cfg)
119123
require.NoError(t, err)
120124

@@ -130,6 +134,7 @@ func TestDuration_UnmarshalYAML(t *testing.T) {
130134
yamlInput := "timeout: 2d3h45m"
131135

132136
var cfg Config
137+
133138
err := yaml.Unmarshal([]byte(yamlInput), &cfg)
134139
require.NoError(t, err)
135140

csyaml/keys.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ func GetDocumentKeys(r io.Reader) ([][]string, error) {
3030
if errors.Is(err, io.EOF) {
3131
break
3232
}
33+
3334
return nil, fmt.Errorf("position %d: %s", idx, yaml.FormatError(err, false, false))
3435
}
36+
3537
keys := []string{}
3638

3739
// Only mapping nodes become MapSlice with UseOrderedMap()

csyaml/merge.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
// Always runs in strict mode: type mismatches or duplicate keys cause an error.
2323
func Merge(inputs [][]byte) (*bytes.Buffer, error) {
2424
var merged any
25+
2526
hasContent := false
27+
2628
for idx, data := range inputs {
2729
dec := yaml.NewDecoder(bytes.NewReader(data), yaml.UseOrderedMap(), yaml.Strict())
2830

@@ -31,8 +33,10 @@ func Merge(inputs [][]byte) (*bytes.Buffer, error) {
3133
if errors.Is(err, io.EOF) {
3234
continue
3335
}
36+
3437
return nil, fmt.Errorf("decoding document %d: %s", idx, yaml.FormatError(err, false, false))
3538
}
39+
3640
hasContent = true
3741

3842
mergedValue, err := mergeValue(merged, value)
@@ -91,8 +95,10 @@ func mergeValue(into, from any) (any, error) {
9195
func mergeMap(into, from yaml.MapSlice) (yaml.MapSlice, error) {
9296
out := make(yaml.MapSlice, len(into))
9397
copy(out, into)
98+
9499
for _, item := range from {
95100
matched := false
101+
96102
for i, existing := range out {
97103
if !reflect.DeepEqual(existing.Key, item.Key) {
98104
continue
@@ -102,13 +108,16 @@ func mergeMap(into, from yaml.MapSlice) (yaml.MapSlice, error) {
102108
if err != nil {
103109
return nil, err
104110
}
111+
105112
out[i].Value = mergedVal
106113
matched = true
107114
}
115+
108116
if !matched {
109117
out = append(out, yaml.MapItem{Key: item.Key, Value: item.Value})
110118
}
111119
}
120+
112121
return out, nil
113122
}
114123

@@ -126,8 +135,10 @@ func describe(i any) string {
126135
if isMapping(i) {
127136
return "mapping"
128137
}
138+
129139
if isSequence(i) {
130140
return "sequence"
131141
}
142+
132143
return "scalar"
133144
}

csyaml/merge_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestMergeYAML(t *testing.T) {
6868

6969
buf, err := csyaml.Merge(bs)
7070
cstest.RequireErrorContains(t, err, tc.wantErr)
71+
7172
if tc.wantErr != "" {
7273
require.Nil(t, buf)
7374
return

csyaml/splityaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func SplitDocumentsDecEnc(r io.Reader) ([][]byte, error) {
3434

3535
enc := yaml.NewEncoder(&buf)
3636
enc.SetIndent(2)
37+
3738
if err := enc.Encode(&node); err != nil {
3839
return nil, fmt.Errorf("encode doc %d: %w", idx, err)
3940
}

0 commit comments

Comments
 (0)