diff options
author | Michael Muré <batolettre@gmail.com> | 2022-02-01 09:24:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-01 09:24:58 +0100 |
commit | 05d73e1b5321c97cd05133b5ae49d1798bc2fe5d (patch) | |
tree | 66eeb4ada52d282ad3ed9e231b3e74b42cbcfa48 /bridge/gitlab/event_test.go | |
parent | 843da8e1f56504efb979f8e5eb43be5c176e7338 (diff) | |
parent | e888391b36307d0d4a1e12ba3a57b602c8b1528a (diff) | |
download | git-bug-05d73e1b5321c97cd05133b5ae49d1798bc2fe5d.tar.gz |
Merge pull request #571 from 5nord/add-new-gitlab-iterator
[gitlab] Add new iterator with state change events
Diffstat (limited to 'bridge/gitlab/event_test.go')
-rw-r--r-- | bridge/gitlab/event_test.go | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/bridge/gitlab/event_test.go b/bridge/gitlab/event_test.go new file mode 100644 index 00000000..860570d1 --- /dev/null +++ b/bridge/gitlab/event_test.go @@ -0,0 +1,95 @@ +package gitlab + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGetNewTitle(t *testing.T) { + type args struct { + diff string + } + type want struct { + title string + } + tests := []struct { + name string + args args + want want + }{ + { + name: "addition diff", + args: args{ + diff: "**first issue** to **first issue{+ edited+}**", + }, + want: want{ + title: "first issue edited", + }, + }, + { + name: "deletion diff", + args: args{ + diff: "**first issue{- edited-}** to **first issue**", + }, + want: want{ + title: "first issue", + }, + }, + { + name: "mixed diff", + args: args{ + diff: "**first {-issue-}** to **first {+bug+}**", + }, + want: want{ + title: "first bug", + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + title := getNewTitle(tt.args.diff) + assert.Equal(t, tt.want.title, title) + }) + } +} + +var _ Event = mockEvent(0) + +type mockEvent int64 + +func (m mockEvent) ID() string { panic("implement me") } +func (m mockEvent) UserID() int { panic("implement me") } +func (m mockEvent) Kind() EventKind { panic("implement me") } +func (m mockEvent) CreatedAt() time.Time { return time.Unix(int64(m), 0) } + +func TestSortedEvents(t *testing.T) { + makeInput := func(times ...int64) chan Event { + out := make(chan Event) + go func() { + for _, t := range times { + out <- mockEvent(t) + } + close(out) + }() + return out + } + + sorted := SortedEvents( + makeInput(), + makeInput(1, 7, 9, 19), + makeInput(2, 8, 23), + makeInput(35, 48, 59, 64, 721), + ) + + var previous Event + for event := range sorted { + if previous != nil { + require.True(t, previous.CreatedAt().Before(event.CreatedAt())) + } + previous = event + } +} |