Skip to content

Commit 4e45b41

Browse files
committed
Replace pkg.Contains with slices.Contains
1 parent b04f9e3 commit 4e45b41

File tree

3 files changed

+3
-71
lines changed

3 files changed

+3
-71
lines changed

src/pkg/cli/client/byoc/aws/stream.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package aws
33
import (
44
"encoding/json"
55
"io"
6+
"slices"
67
"strings"
78
"time"
89

@@ -118,7 +119,7 @@ func (bs *byocServerStream) parseEvents(events []ecs.LogEvent) *defangv1.TailRes
118119
return nil // TODO: filter these out using the AWS StartLiveTail API
119120
}
120121

121-
if len(bs.services) > 0 && !pkg.Contains(bs.services, response.GetService()) {
122+
if len(bs.services) > 0 && !slices.Contains(bs.services, response.GetService()) {
122123
return nil // TODO: filter these out using the AWS StartLiveTail API
123124
}
124125

@@ -157,7 +158,7 @@ func (bs *byocServerStream) parseEvents(events []ecs.LogEvent) *defangv1.TailRes
157158
if entry.Etag != "" && bs.etag != "" && entry.Etag != bs.etag {
158159
continue
159160
}
160-
if entry.Service != "" && len(bs.services) > 0 && !pkg.Contains(bs.services, entry.Service) {
161+
if entry.Service != "" && len(bs.services) > 0 && !slices.Contains(bs.services, entry.Service) {
161162
continue
162163
}
163164
entries = append(entries, entry)

src/pkg/utils.go

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

33
import (
44
"context"
5-
"encoding/json"
65
"io"
76
"math/rand"
87
"os"
@@ -62,21 +61,6 @@ func SplitByComma(s string) []string {
6261
return strings.Split(s, ",")
6362
}
6463

65-
type OneOrList []string
66-
67-
func (l *OneOrList) UnmarshalJSON(data []byte) error {
68-
ls := []string{}
69-
if err := json.Unmarshal(data, &ls); err != nil {
70-
var s string
71-
if err := json.Unmarshal(data, &s); err != nil {
72-
return err
73-
}
74-
ls = []string{s}
75-
}
76-
*l = ls
77-
return nil
78-
}
79-
8064
func RandomID() string {
8165
const uint64msb = 1 << 63 // always set the MSB to ensure we get ≥12 digits
8266
return strconv.FormatUint(rand.Uint64()|uint64msb, 36)[1:]
@@ -118,15 +102,6 @@ func SleepWithContext(ctx context.Context, d time.Duration) error {
118102
}
119103
}
120104

121-
func Contains[T comparable](s []T, v T) bool {
122-
for _, val := range s {
123-
if val == v {
124-
return true
125-
}
126-
}
127-
return false
128-
}
129-
130105
func SubscriptionTierToString(tier defangv1.SubscriptionTier) string {
131106
switch tier {
132107
case defangv1.SubscriptionTier_SUBSCRIPTION_TIER_UNSPECIFIED:

src/pkg/utils_test.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package pkg
22

33
import (
4-
"encoding/json"
54
"reflect"
65
"testing"
76
"time"
@@ -103,27 +102,6 @@ func TestSplitByComma(t *testing.T) {
103102
}
104103
}
105104

106-
func TestOneOrList(t *testing.T) {
107-
tests := []struct {
108-
name string
109-
in string
110-
want []string
111-
}{
112-
{"empty", `[]`, []string{}},
113-
{"string", `"a"`, []string{"a"}},
114-
{"one", `["a"]`, []string{"a"}},
115-
{"two", `["a","b"]`, []string{"a", "b"}},
116-
}
117-
for _, tt := range tests {
118-
t.Run(tt.name, func(t *testing.T) {
119-
var got OneOrList
120-
if err := json.Unmarshal([]byte(tt.in), &got); err != nil || !reflect.DeepEqual([]string(got), tt.want) {
121-
t.Errorf("OneOrList(%v) = %v, want %v: %v", tt.in, got, tt.want, err)
122-
}
123-
})
124-
}
125-
}
126-
127105
func TestRandomID(t *testing.T) {
128106
var unique = make(map[string]bool)
129107
for range 100 {
@@ -138,28 +116,6 @@ func TestRandomID(t *testing.T) {
138116
}
139117
}
140118

141-
func TestContains(t *testing.T) {
142-
tests := []struct {
143-
name string
144-
slice []int
145-
value int
146-
expected bool
147-
}{
148-
{"Empty slice", []int{}, 1, false},
149-
{"Single element", []int{1}, 1, true},
150-
{"Multiple elements", []int{1, 2, 3, 4, 5}, 3, true},
151-
{"Non-existent element", []int{1, 2, 3, 4, 5}, 6, false},
152-
}
153-
154-
for _, tt := range tests {
155-
t.Run(tt.name, func(t *testing.T) {
156-
if got := Contains(tt.slice, tt.value); got != tt.expected {
157-
t.Errorf("Contains() returned %v, expected %v", got, tt.expected)
158-
}
159-
})
160-
}
161-
}
162-
163119
func TestIsValidTime(t *testing.T) {
164120
tests := []struct {
165121
name string

0 commit comments

Comments
 (0)