Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'workhorse/internal/channel/auth_checker_test.go')
-rw-r--r--workhorse/internal/channel/auth_checker_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/workhorse/internal/channel/auth_checker_test.go b/workhorse/internal/channel/auth_checker_test.go
new file mode 100644
index 00000000000..18beb45cf3a
--- /dev/null
+++ b/workhorse/internal/channel/auth_checker_test.go
@@ -0,0 +1,53 @@
+package channel
+
+import (
+ "testing"
+ "time"
+
+ "gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
+)
+
+func checkerSeries(values ...*api.ChannelSettings) AuthCheckerFunc {
+ return func() *api.ChannelSettings {
+ if len(values) == 0 {
+ return nil
+ }
+ out := values[0]
+ values = values[1:]
+ return out
+ }
+}
+
+func TestAuthCheckerStopsWhenAuthFails(t *testing.T) {
+ template := &api.ChannelSettings{Url: "ws://example.com"}
+ stopCh := make(chan error)
+ series := checkerSeries(template, template, template)
+ ac := NewAuthChecker(series, template, stopCh)
+
+ go ac.Loop(1 * time.Millisecond)
+ if err := <-stopCh; err != ErrAuthChanged {
+ t.Fatalf("Expected ErrAuthChanged, got %v", err)
+ }
+
+ if ac.Count != 3 {
+ t.Fatalf("Expected 3 successful checks, got %v", ac.Count)
+ }
+}
+
+func TestAuthCheckerStopsWhenAuthChanges(t *testing.T) {
+ template := &api.ChannelSettings{Url: "ws://example.com"}
+ changed := template.Clone()
+ changed.Url = "wss://example.com"
+ stopCh := make(chan error)
+ series := checkerSeries(template, changed, template)
+ ac := NewAuthChecker(series, template, stopCh)
+
+ go ac.Loop(1 * time.Millisecond)
+ if err := <-stopCh; err != ErrAuthChanged {
+ t.Fatalf("Expected ErrAuthChanged, got %v", err)
+ }
+
+ if ac.Count != 1 {
+ t.Fatalf("Expected 1 successful check, got %v", ac.Count)
+ }
+}