|
| 1 | +// Copyright (c) 2026 Uber Technologies, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package fake |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "errors" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | + "github.com/stretchr/testify/require" |
| 24 | + |
| 25 | + "github.com/uber/submitqueue/submitqueue/entity" |
| 26 | +) |
| 27 | + |
| 28 | +func TestGet(t *testing.T) { |
| 29 | + frozen := entity.QueuePause{FreezeProcessing: true, Reason: "incident"} |
| 30 | + tests := []struct { |
| 31 | + name string |
| 32 | + setup func(*Store) |
| 33 | + queue string |
| 34 | + want entity.QueuePause |
| 35 | + }{ |
| 36 | + {name: "queue never set is not paused", setup: func(*Store) {}, queue: "q", want: entity.QueuePause{}}, |
| 37 | + {name: "queue set is returned", setup: func(s *Store) { s.Set("q", frozen) }, queue: "q", want: frozen}, |
| 38 | + {name: "other queue is unaffected", setup: func(s *Store) { s.Set("q", frozen) }, queue: "other", want: entity.QueuePause{}}, |
| 39 | + {name: "setting the zero state unpauses", setup: func(s *Store) { s.Set("q", frozen).Set("q", entity.QueuePause{}) }, queue: "q", want: entity.QueuePause{}}, |
| 40 | + } |
| 41 | + for _, tt := range tests { |
| 42 | + t.Run(tt.name, func(t *testing.T) { |
| 43 | + s := New() |
| 44 | + tt.setup(s) |
| 45 | + |
| 46 | + got, err := s.Get(context.Background(), tt.queue) |
| 47 | + require.NoError(t, err) |
| 48 | + assert.Equal(t, tt.want, got) |
| 49 | + }) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +func TestFailWith(t *testing.T) { |
| 54 | + boom := errors.New("backend down") |
| 55 | + s := New().Set("q", entity.QueuePause{RejectLands: true}).FailWith(boom) |
| 56 | + |
| 57 | + got, err := s.Get(context.Background(), "q") |
| 58 | + require.ErrorIs(t, err, boom) |
| 59 | + assert.Equal(t, entity.QueuePause{}, got) |
| 60 | + |
| 61 | + got, err = s.FailWith(nil).Get(context.Background(), "q") |
| 62 | + require.NoError(t, err) |
| 63 | + assert.Equal(t, entity.QueuePause{RejectLands: true}, got) |
| 64 | +} |
0 commit comments