github.com/googleapis/api-linter@v1.65.2/cmd/api-linter/summary_test.go (about) 1 // Copyright 2019 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 main 16 17 import ( 18 "testing" 19 20 "github.com/google/go-cmp/cmp" 21 "github.com/googleapis/api-linter/lint" 22 ) 23 24 func TestCreateSummary(t *testing.T) { 25 tests := []struct { 26 name string 27 data []lint.Response 28 wantSummary map[string]map[string]int 29 }{{ 30 name: "Empty input", 31 data: []lint.Response{}, 32 wantSummary: make(map[string]map[string]int), 33 }, { 34 name: "Example with a couple of responses", 35 data: []lint.Response{ 36 { 37 FilePath: "example.proto", 38 Problems: []lint.Problem{ 39 {RuleID: "core::naming_formats::field_names"}, 40 {RuleID: "core::naming_formats::field_names"}, 41 }, 42 }, 43 { 44 FilePath: "example2.proto", 45 Problems: []lint.Problem{ 46 {RuleID: "core::0131::request_message::name"}, 47 {RuleID: "core::0132::response_message::name"}, 48 }, 49 }, 50 { 51 FilePath: "example3.proto", 52 Problems: []lint.Problem{ 53 {RuleID: "core::naming_formats::field_names"}, 54 }, 55 }, 56 { 57 FilePath: "example4.proto", 58 Problems: []lint.Problem{ 59 {RuleID: "core::naming_formats::field_names"}, 60 {RuleID: "core::0132::response_message::name"}, 61 }, 62 }, 63 }, 64 wantSummary: map[string]map[string]int{ 65 "core::0131::request_message::name": {"example2.proto": 1}, 66 "core::0132::response_message::name": { 67 "example2.proto": 1, 68 "example4.proto": 1, 69 }, 70 "core::naming_formats::field_names": { 71 "example.proto": 2, 72 "example3.proto": 1, 73 "example4.proto": 1, 74 }, 75 }, 76 }} 77 for _, test := range tests { 78 want := test.wantSummary 79 got := createSummary(test.data) 80 if diff := cmp.Diff(want, got); diff != "" { 81 t.Errorf("createSummary() mismatch (-want +got):\n%s", diff) 82 } 83 } 84 }