Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Install Go
uses: buildjet/setup-go@v5
with:
go-version: 1.22.x
go-version: 1.25.x
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup Go
uses: buildjet/setup-go@v5
with:
go-version: v1.22.x
go-version: v1.25.x
- uses: buildjet/cache@v4
with:
path: |
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ jobs:
matrix:
platform: [ubuntu-latest]
go-version:
- 1.23.x
- 1.24.x
- 1.25.x
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ test:

.PHONY: lint
lint:
golangci-lint run
mkdir -p bin
GOBIN=$(shell realpath bin) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0
./bin/golangci-lint run

.PHONY: tidy
tidy:
go mod tidy
go mod tidy

13 changes: 13 additions & 0 deletions collections/collections_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package collections

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestCollections(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Collections Suite")
}
244 changes: 128 additions & 116 deletions collections/collections_test.go
Original file line number Diff line number Diff line change
@@ -1,121 +1,133 @@
package collections

import (
"reflect"
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func Test_MergeMap(t *testing.T) {
type args struct {
a map[string]string
b map[string]string
}
tests := []struct {
name string
args args
want map[string]string
}{
{
name: "no overlaps",
args: args{
a: map[string]string{"name": "flanksource"},
b: map[string]string{"foo": "bar"},
},
want: map[string]string{
"name": "flanksource",
"foo": "bar",
},
},
{
name: "overlaps",
args: args{
a: map[string]string{"name": "flanksource", "foo": "baz"},
b: map[string]string{"foo": "bar"},
},
want: map[string]string{
"name": "flanksource",
"foo": "bar",
},
},
{
name: "overlaps II",
args: args{
a: map[string]string{"name": "github", "foo": "baz"},
b: map[string]string{"name": "flanksource", "foo": "bar"},
},
want: map[string]string{
"name": "flanksource",
"foo": "bar",
},
},
{
name: "ditto",
args: args{
a: map[string]string{"name": "flanksource", "foo": "bar"},
b: map[string]string{"name": "flanksource", "foo": "bar"},
},
want: map[string]string{
"name": "flanksource",
"foo": "bar",
},
},
{
name: "nil a",
args: args{
a: nil,
b: map[string]string{"name": "flanksource", "foo": "bar"},
},
want: map[string]string{
"name": "flanksource",
"foo": "bar",
},
},
{
name: "nil b",
args: args{
a: map[string]string{"name": "flanksource", "foo": "bar"},
b: nil,
},
want: map[string]string{
"name": "flanksource",
"foo": "bar",
},
},
{
name: "both nil",
args: args{
a: nil,
b: nil,
},
want: map[string]string{},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MergeMap(tt.args.a, tt.args.b); !reflect.DeepEqual(got, tt.want) {
t.Errorf("got %v, want %v", got, tt.want)
}
})
}
}

func Test_KeyValueSliceToMap(t *testing.T) {
tests := []struct {
name string
args []string
want map[string]string
}{
{name: "simple", args: []string{"name=flanksource"}, want: map[string]string{"name": "flanksource"}},
{name: "white space", args: []string{" name = flanksource "}, want: map[string]string{"name": "flanksource"}},
{name: "multiple-simple", args: []string{"name=flanksource", "foo=bar"}, want: map[string]string{"name": "flanksource", "foo": "bar"}},
{name: "double-equal", args: []string{"name=foo=bar"}, want: map[string]string{"name": "foo=bar"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := KeyValueSliceToMap(tt.args); !reflect.DeepEqual(got, tt.want) {
t.Errorf("got %v, want %v", got, tt.want)
}
})
}
}
var _ = Describe("MergeMap", func() {
It("should merge maps with no overlaps", func() {
a := map[string]string{"name": "flanksource"}
b := map[string]string{"foo": "bar"}
expected := map[string]string{
"name": "flanksource",
"foo": "bar",
}

result := MergeMap(a, b)

Expect(result).To(Equal(expected))
})

It("should merge maps with overlaps, b takes precedence", func() {
a := map[string]string{"name": "flanksource", "foo": "baz"}
b := map[string]string{"foo": "bar"}
expected := map[string]string{
"name": "flanksource",
"foo": "bar",
}

result := MergeMap(a, b)

Expect(result).To(Equal(expected))
})

It("should merge maps with multiple overlaps", func() {
a := map[string]string{"name": "github", "foo": "baz"}
b := map[string]string{"name": "flanksource", "foo": "bar"}
expected := map[string]string{
"name": "flanksource",
"foo": "bar",
}

result := MergeMap(a, b)

Expect(result).To(Equal(expected))
})

It("should handle identical maps", func() {
a := map[string]string{"name": "flanksource", "foo": "bar"}
b := map[string]string{"name": "flanksource", "foo": "bar"}
expected := map[string]string{
"name": "flanksource",
"foo": "bar",
}

result := MergeMap(a, b)

Expect(result).To(Equal(expected))
})

It("should handle nil first map", func() {
var a map[string]string
b := map[string]string{"name": "flanksource", "foo": "bar"}
expected := map[string]string{
"name": "flanksource",
"foo": "bar",
}

result := MergeMap(a, b)

Expect(result).To(Equal(expected))
})

It("should handle nil second map", func() {
a := map[string]string{"name": "flanksource", "foo": "bar"}
var b map[string]string
expected := map[string]string{
"name": "flanksource",
"foo": "bar",
}

result := MergeMap(a, b)

Expect(result).To(Equal(expected))
})

It("should handle both maps nil", func() {
var a, b map[string]string
expected := map[string]string{}

result := MergeMap(a, b)

Expect(result).To(Equal(expected))
})
})

var _ = Describe("KeyValueSliceToMap", func() {
It("should convert simple key=value pair", func() {
args := []string{"name=flanksource"}
expected := map[string]string{"name": "flanksource"}

result := KeyValueSliceToMap(args)

Expect(result).To(Equal(expected))
})

It("should handle whitespace around key=value pairs", func() {
args := []string{" name = flanksource "}
expected := map[string]string{"name": "flanksource"}

result := KeyValueSliceToMap(args)

Expect(result).To(Equal(expected))
})

It("should convert multiple key=value pairs", func() {
args := []string{"name=flanksource", "foo=bar"}
expected := map[string]string{"name": "flanksource", "foo": "bar"}

result := KeyValueSliceToMap(args)

Expect(result).To(Equal(expected))
})

It("should handle values with equal signs", func() {
args := []string{"name=foo=bar"}
expected := map[string]string{"name": "foo=bar"}

result := KeyValueSliceToMap(args)

Expect(result).To(Equal(expected))
})
})
46 changes: 16 additions & 30 deletions collections/maps_test.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
package collections

import "testing"
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestSortedMap(t *testing.T) {
type args struct {
labels map[string]string
}
tests := []struct {
name string
args args
want string
}{
{
name: "simple",
args: args{
labels: map[string]string{
"b": "b",
"a": "a",
"c": "c",
},
},
want: "a=a,b=b,c=c",
},
}
var _ = Describe("SortedMap", func() {
It("should sort map entries alphabetically", func() {
labels := map[string]string{
"b": "b",
"a": "a",
"c": "c",
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SortedMap(tt.args.labels); got != tt.want {
t.Errorf("SortedMap() = %v, want %v", got, tt.want)
}
})
}
}
result := SortedMap(labels)

Expect(result).To(Equal("a=a,b=b,c=c"))
})
})
Loading
Loading