|
| 1 | +// Copyright (c) 2025 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 mapper |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "github.com/stretchr/testify/assert" |
| 21 | + pb "github.com/uber/submitqueue/api/submitqueue/gateway/protopb" |
| 22 | + "github.com/uber/submitqueue/submitqueue/core/request" |
| 23 | + "github.com/uber/submitqueue/submitqueue/entity" |
| 24 | +) |
| 25 | + |
| 26 | +func TestProtoToStatusRequest(t *testing.T) { |
| 27 | + tests := []struct { |
| 28 | + name string |
| 29 | + req *pb.StatusRequest |
| 30 | + expected entity.StatusRequest |
| 31 | + }{ |
| 32 | + { |
| 33 | + name: "maps sqid to ID", |
| 34 | + req: &pb.StatusRequest{Sqid: "test-queue/42"}, |
| 35 | + expected: entity.StatusRequest{ID: "test-queue/42"}, |
| 36 | + }, |
| 37 | + { |
| 38 | + name: "empty request yields zero value", |
| 39 | + req: &pb.StatusRequest{}, |
| 40 | + expected: entity.StatusRequest{}, |
| 41 | + }, |
| 42 | + } |
| 43 | + |
| 44 | + for _, tt := range tests { |
| 45 | + t.Run(tt.name, func(t *testing.T) { |
| 46 | + got := ProtoToStatusRequest(tt.req) |
| 47 | + assert.Equal(t, tt.expected, got) |
| 48 | + }) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func TestCurrentStateToProto(t *testing.T) { |
| 53 | + tests := []struct { |
| 54 | + name string |
| 55 | + state request.CurrentState |
| 56 | + expected *pb.StatusResponse |
| 57 | + }{ |
| 58 | + { |
| 59 | + name: "maps all fields", |
| 60 | + state: request.CurrentState{ |
| 61 | + Status: entity.RequestStatusValidating, |
| 62 | + LastError: "validation failed", |
| 63 | + Metadata: map[string]string{"step": "lint"}, |
| 64 | + }, |
| 65 | + expected: &pb.StatusResponse{ |
| 66 | + Status: string(entity.RequestStatusValidating), |
| 67 | + LastError: "validation failed", |
| 68 | + Metadata: map[string]string{"step": "lint"}, |
| 69 | + }, |
| 70 | + }, |
| 71 | + { |
| 72 | + name: "zero value state maps to empty response", |
| 73 | + state: request.CurrentState{}, |
| 74 | + expected: &pb.StatusResponse{ |
| 75 | + Status: "", |
| 76 | + }, |
| 77 | + }, |
| 78 | + } |
| 79 | + |
| 80 | + for _, tt := range tests { |
| 81 | + t.Run(tt.name, func(t *testing.T) { |
| 82 | + got := CurrentStateToProto(tt.state) |
| 83 | + assert.Equal(t, tt.expected, got) |
| 84 | + }) |
| 85 | + } |
| 86 | +} |
0 commit comments