2022-10-12 11:04:32 -07:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2022-10-12 11:04:32 -07:00
|
|
|
package metric
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/gen/testing/protooptions"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"google.golang.org/protobuf/reflect/protoreflect"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// As is, this test will currently fail if the services and methods in the protooptions
|
|
|
|
|
// package are changed. Please use temporary testcases to manually debug.
|
|
|
|
|
func Test_AppendServicesAndMethods(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
|
name string
|
|
|
|
|
pkg protoreflect.FileDescriptor
|
2022-12-12 09:12:33 -08:00
|
|
|
filter func(string, string) bool
|
2022-10-12 11:04:32 -07:00
|
|
|
expected map[string][]string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "basic",
|
|
|
|
|
pkg: protooptions.File_testing_options_v1_service_proto,
|
2022-12-12 09:12:33 -08:00
|
|
|
filter: func(string, string) bool { return false },
|
|
|
|
|
expected: map[string][]string{"testing.options.v1.TestService": {"TestMethod"}},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "filter-out",
|
|
|
|
|
pkg: protooptions.File_testing_options_v1_service_proto,
|
|
|
|
|
filter: func(_ string, m string) bool {
|
|
|
|
|
return m == "TestMethod"
|
|
|
|
|
},
|
|
|
|
|
expected: map[string][]string{},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "filter-allow",
|
|
|
|
|
pkg: protooptions.File_testing_options_v1_service_proto,
|
|
|
|
|
filter: func(_ string, m string) bool {
|
|
|
|
|
return m != "TestMethod"
|
|
|
|
|
},
|
2022-10-12 11:04:32 -07:00
|
|
|
expected: map[string][]string{"testing.options.v1.TestService": {"TestMethod"}},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
|
m := make(map[string][]string, 0)
|
2022-12-12 09:12:33 -08:00
|
|
|
appendServicesAndMethods(m, tc.pkg, tc.filter)
|
2022-10-12 11:04:32 -07:00
|
|
|
assert.Equal(t, tc.expected, m)
|
|
|
|
|
}
|
|
|
|
|
}
|