|
| 1 | +// Copyright 2025 Google LLC |
| 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 | +// https://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 api |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "github.com/google/go-cmp/cmp" |
| 21 | +) |
| 22 | + |
| 23 | +func TestLroServices(t *testing.T) { |
| 24 | + d := &Discovery{ |
| 25 | + Pollers: []*Poller{ |
| 26 | + {Prefix: "p1", MethodID: "Service1.Method1"}, |
| 27 | + {Prefix: "p2", MethodID: "Service1.Method2"}, |
| 28 | + {Prefix: "p3", MethodID: "Service2.Method3"}, |
| 29 | + }, |
| 30 | + } |
| 31 | + want := map[string]bool{ |
| 32 | + "Service1": true, |
| 33 | + "Service2": true, |
| 34 | + } |
| 35 | + got := d.LroServices() |
| 36 | + if diff := cmp.Diff(want, got); diff != "" { |
| 37 | + t.Errorf("LroServices() mismatch (-want +got):\n%s", diff) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func TestPathParameters(t *testing.T) { |
| 42 | + tests := []struct { |
| 43 | + name string |
| 44 | + input *Poller |
| 45 | + want []string |
| 46 | + }{ |
| 47 | + { |
| 48 | + name: "multiple parameters", |
| 49 | + input: &Poller{Prefix: "projects/{project}/zones/{zone}"}, |
| 50 | + want: []string{"project", "zone"}, |
| 51 | + }, |
| 52 | + { |
| 53 | + name: "no parameters", |
| 54 | + input: &Poller{Prefix: "abc/def"}, |
| 55 | + want: nil, |
| 56 | + }, |
| 57 | + { |
| 58 | + name: "single parameter", |
| 59 | + input: &Poller{Prefix: "a/{b}"}, |
| 60 | + want: []string{"b"}, |
| 61 | + }, |
| 62 | + } |
| 63 | + for _, test := range tests { |
| 64 | + t.Run(test.name, func(t *testing.T) { |
| 65 | + got := test.input.PathParameters() |
| 66 | + if diff := cmp.Diff(test.want, got); diff != "" { |
| 67 | + t.Errorf("PathParameters(%q) mismatch (-want +got):\n%s", test.input.Prefix, diff) |
| 68 | + } |
| 69 | + }) |
| 70 | + } |
| 71 | +} |
0 commit comments