Skip to content

Commit

Permalink
Signal: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hovsep committed Oct 3, 2024
1 parent 9c5e351 commit e4b665b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
3 changes: 0 additions & 3 deletions signal/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ func (group Group) With(signals ...*Signal) Group {
newGroup := make(Group, len(group)+len(signals))
copy(newGroup, group)
for i, sig := range signals {
if sig == nil {
continue
}
newGroup[len(group)+i] = sig
}

Expand Down
100 changes: 100 additions & 0 deletions signal/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,103 @@ func TestGroup_AllPayloads(t *testing.T) {
})
}
}

func TestGroup_With(t *testing.T) {
type args struct {
signals []*Signal
}
tests := []struct {
name string
group Group
args args
want Group
}{
{
name: "no addition to empty group",
group: NewGroup(),
args: args{
signals: nil,
},
want: NewGroup(),
},
{
name: "no addition to group",
group: NewGroup(1, 2, 3),
args: args{
signals: nil,
},
want: NewGroup(1, 2, 3),
},
{
name: "addition to empty group",
group: NewGroup(),
args: args{
signals: NewGroup(3, 4, 5),
},
want: NewGroup(3, 4, 5),
},
{
name: "addition to group",
group: NewGroup(1, 2, 3),
args: args{
signals: NewGroup(4, 5, 6),
},
want: NewGroup(1, 2, 3, 4, 5, 6),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.group.With(tt.args.signals...))
})
}
}

func TestGroup_WithPayloads(t *testing.T) {
type args struct {
payloads []any
}
tests := []struct {
name string
group Group
args args
want Group
}{
{
name: "no addition to empty group",
group: NewGroup(),
args: args{
payloads: nil,
},
want: NewGroup(),
},
{
name: "addition to empty group",
group: NewGroup(),
args: args{
payloads: []any{1, 2, 3},
},
want: NewGroup(1, 2, 3),
},
{
name: "no addition to group",
group: NewGroup(1, 2, 3),
args: args{
payloads: nil,
},
want: NewGroup(1, 2, 3),
},
{
name: "addition to group",
group: NewGroup(1, 2, 3),
args: args{
payloads: []any{4, 5, 6},
},
want: NewGroup(1, 2, 3, 4, 5, 6),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.group.WithPayloads(tt.args.payloads...))
})
}
}

0 comments on commit e4b665b

Please sign in to comment.