From 4ec2dc9e47f801403502dc7eea4b4b028d9b9f1b Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Wed, 15 Apr 2020 09:02:28 -0700 Subject: [PATCH] Minor reorganization in tests --- processor_test.go | 80 ++++++++++++++++++++++++++++++++++++++++++++++ server_test.go | 81 ----------------------------------------------- 2 files changed, 80 insertions(+), 81 deletions(-) diff --git a/processor_test.go b/processor_test.go index 6ba48df..af015e4 100644 --- a/processor_test.go +++ b/processor_test.go @@ -482,3 +482,83 @@ func TestCreateContextWithoutTimeRestrictions(t *testing.T) { t.Error("ctx.Done() blocked, want it to be non-blocking") } } + +func TestGCD(t *testing.T) { + tests := []struct { + input []int + want int + }{ + {[]int{6, 2, 12}, 2}, + {[]int{3, 3, 3}, 3}, + {[]int{6, 3, 1}, 1}, + {[]int{1}, 1}, + {[]int{1, 0, 2}, 1}, + {[]int{8, 0, 4}, 4}, + {[]int{9, 12, 18, 30}, 3}, + } + + for _, tc := range tests { + got := gcd(tc.input...) + if got != tc.want { + t.Errorf("gcd(%v) = %d, want %d", tc.input, got, tc.want) + } + } +} + +func TestNormalizeQueueCfg(t *testing.T) { + tests := []struct { + input map[string]int + want map[string]int + }{ + { + input: map[string]int{ + "high": 100, + "default": 20, + "low": 5, + }, + want: map[string]int{ + "high": 20, + "default": 4, + "low": 1, + }, + }, + { + input: map[string]int{ + "default": 10, + }, + want: map[string]int{ + "default": 1, + }, + }, + { + input: map[string]int{ + "critical": 5, + "default": 1, + }, + want: map[string]int{ + "critical": 5, + "default": 1, + }, + }, + { + input: map[string]int{ + "critical": 6, + "default": 3, + "low": 0, + }, + want: map[string]int{ + "critical": 2, + "default": 1, + "low": 0, + }, + }, + } + + for _, tc := range tests { + got := normalizeQueueCfg(tc.input) + if diff := cmp.Diff(tc.want, got); diff != "" { + t.Errorf("normalizeQueueCfg(%v) = %v, want %v; (-want, +got):\n%s", + tc.input, got, tc.want, diff) + } + } +} diff --git a/server_test.go b/server_test.go index cb56ad4..fe2d976 100644 --- a/server_test.go +++ b/server_test.go @@ -9,7 +9,6 @@ import ( "testing" "time" - "github.com/google/go-cmp/cmp" "go.uber.org/goleak" ) @@ -84,83 +83,3 @@ func TestServerErrServerRunning(t *testing.T) { } srv.Stop() } - -func TestGCD(t *testing.T) { - tests := []struct { - input []int - want int - }{ - {[]int{6, 2, 12}, 2}, - {[]int{3, 3, 3}, 3}, - {[]int{6, 3, 1}, 1}, - {[]int{1}, 1}, - {[]int{1, 0, 2}, 1}, - {[]int{8, 0, 4}, 4}, - {[]int{9, 12, 18, 30}, 3}, - } - - for _, tc := range tests { - got := gcd(tc.input...) - if got != tc.want { - t.Errorf("gcd(%v) = %d, want %d", tc.input, got, tc.want) - } - } -} - -func TestNormalizeQueueCfg(t *testing.T) { - tests := []struct { - input map[string]int - want map[string]int - }{ - { - input: map[string]int{ - "high": 100, - "default": 20, - "low": 5, - }, - want: map[string]int{ - "high": 20, - "default": 4, - "low": 1, - }, - }, - { - input: map[string]int{ - "default": 10, - }, - want: map[string]int{ - "default": 1, - }, - }, - { - input: map[string]int{ - "critical": 5, - "default": 1, - }, - want: map[string]int{ - "critical": 5, - "default": 1, - }, - }, - { - input: map[string]int{ - "critical": 6, - "default": 3, - "low": 0, - }, - want: map[string]int{ - "critical": 2, - "default": 1, - "low": 0, - }, - }, - } - - for _, tc := range tests { - got := normalizeQueueCfg(tc.input) - if diff := cmp.Diff(tc.want, got); diff != "" { - t.Errorf("normalizeQueueCfg(%v) = %v, want %v; (-want, +got):\n%s", - tc.input, got, tc.want, diff) - } - } -}