| 1 |
// Copyright 2020 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 |
// 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 generator |
| 16 |
|
| 17 |
import "testing" |
| 18 |
|
| 19 |
func TestFilterPackages(t *testing.T) { |
| 20 |
in := map[string][]string{ |
| 21 |
"google.golang.org/genproto/googleapis/api/distribution": {"foo.proto"}, |
| 22 |
"google.golang.org/genproto/googleapis/type/date_range": {"foo.proto"}, |
| 23 |
"google.golang.org/genproto/googleapis/bigtable/admin/v2": {"foo.proto"}, |
| 24 |
// Should be excluded. |
| 25 |
"google.golang.org/genproto/do/not/generate/me": {"foo.proto"}, |
| 26 |
} |
| 27 |
want := map[string][]string{ |
| 28 |
"google.golang.org/genproto/googleapis/api/distribution": {"foo.proto"}, |
| 29 |
"google.golang.org/genproto/googleapis/type/date_range": {"foo.proto"}, |
| 30 |
} |
| 31 |
out, err := filterPackages(in) |
| 32 |
if err != nil { |
| 33 |
t.Fatal(err) |
| 34 |
} |
| 35 |
|
| 36 |
if len(out) != len(want) { |
| 37 |
t.Fatalf("expected %d packages got %d packages", len(want), len(out)) |
| 38 |
} |
| 39 |
for p := range out { |
| 40 |
if _, ok := want[p]; !ok { |
| 41 |
t.Errorf("retained package that should have been removed: %q", p) |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
} |