mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
184 lines
4.9 KiB
Go
184 lines
4.9 KiB
Go
package interceptor
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
"go.temporal.io/api/workflowservice/v1"
|
|
"go.temporal.io/server/api/historyservice/v1"
|
|
"go.temporal.io/server/api/matchingservice/v1"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
type (
|
|
namespaceSuite struct {
|
|
suite.Suite
|
|
*require.Assertions
|
|
}
|
|
)
|
|
|
|
var (
|
|
frontendAPIExcluded = map[string]struct{}{
|
|
"GetClusterInfo": {},
|
|
"GetSystemInfo": {},
|
|
"GetSearchAttributes": {},
|
|
"ListNamespaces": {},
|
|
}
|
|
|
|
matchingAPIExcluded = map[string]struct{}{
|
|
"ListTaskQueuePartitions": {},
|
|
// Nexus endpoint APIs operate on a cluster scope, not a namespace scope.
|
|
"CreateNexusEndpoint": {},
|
|
"UpdateNexusEndpoint": {},
|
|
"ListNexusEndpoints": {},
|
|
"DeleteNexusEndpoint": {},
|
|
}
|
|
|
|
historyAPIExcluded = map[string]struct{}{
|
|
"CloseShard": {},
|
|
"GetShard": {},
|
|
"GetDLQMessages": {},
|
|
"GetDLQReplicationMessages": {},
|
|
"GetReplicationMessages": {},
|
|
"MergeDLQMessages": {},
|
|
"PurgeDLQMessages": {},
|
|
"RemoveTask": {},
|
|
"SyncShardStatus": {},
|
|
"GetReplicationStatus": {},
|
|
"GetDLQTasks": {},
|
|
"DeleteDLQTasks": {},
|
|
"AddTasks": {},
|
|
"ListQueues": {},
|
|
"ListTasks": {},
|
|
"CompleteNexusOperation": {}, // NamespaceId is in the completion token for this request.
|
|
"DeepHealthCheck": {},
|
|
}
|
|
)
|
|
|
|
func TestNamespaceSuite(t *testing.T) {
|
|
s := new(namespaceSuite)
|
|
suite.Run(t, s)
|
|
}
|
|
|
|
func (s *namespaceSuite) SetupTest() {
|
|
s.Assertions = require.New(s.T())
|
|
}
|
|
|
|
func (s *namespaceSuite) TearDownTest() {
|
|
|
|
}
|
|
|
|
func (s *namespaceSuite) TestFrontendAPIMetrics() {
|
|
namespaceNameGetter := reflect.TypeOf((*NamespaceNameGetter)(nil)).Elem()
|
|
|
|
var service workflowservice.WorkflowServiceServer
|
|
t := reflect.TypeOf(&service).Elem()
|
|
for i := 0; i < t.NumMethod(); i++ {
|
|
method := t.Method(i)
|
|
methodName := method.Name
|
|
methodType := method.Type
|
|
|
|
// 0th parameter is context.Context
|
|
// 1th parameter is the request
|
|
if _, ok := frontendAPIExcluded[methodName]; ok {
|
|
continue
|
|
}
|
|
if methodType.NumIn() < 2 {
|
|
continue
|
|
}
|
|
request := methodType.In(1)
|
|
if !request.Implements(namespaceNameGetter) {
|
|
s.Fail(fmt.Sprintf("API: %v not implementing NamespaceNameGetter", methodName))
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *namespaceSuite) TestMatchingAPIMetrics() {
|
|
namespaceIDGetter := reflect.TypeOf((*NamespaceIDGetter)(nil)).Elem()
|
|
|
|
var service matchingservice.MatchingServiceServer
|
|
t := reflect.TypeOf(&service).Elem()
|
|
for i := 0; i < t.NumMethod(); i++ {
|
|
method := t.Method(i)
|
|
methodName := method.Name
|
|
methodType := method.Type
|
|
|
|
// 0th parameter is context.Context
|
|
// 1th parameter is the request
|
|
if _, ok := matchingAPIExcluded[methodName]; ok {
|
|
continue
|
|
}
|
|
if methodType.NumIn() < 2 {
|
|
continue
|
|
}
|
|
request := methodType.In(1)
|
|
if !request.Implements(namespaceIDGetter) {
|
|
s.Fail(fmt.Sprintf("API: %v not implementing NamespaceIDGetter", methodName))
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *namespaceSuite) TestHistoryAPIMetrics() {
|
|
namespaceIDGetter := reflect.TypeOf((*NamespaceIDGetter)(nil)).Elem()
|
|
|
|
var service historyservice.HistoryServiceServer
|
|
t := reflect.TypeOf(&service).Elem()
|
|
for i := 0; i < t.NumMethod(); i++ {
|
|
method := t.Method(i)
|
|
methodName := method.Name
|
|
methodType := method.Type
|
|
|
|
// 0th parameter is context.Context
|
|
// 1th parameter is the request
|
|
if _, ok := historyAPIExcluded[methodName]; ok {
|
|
continue
|
|
}
|
|
if methodType.NumIn() < 2 {
|
|
continue
|
|
}
|
|
request := methodType.In(1)
|
|
if !request.Implements(namespaceIDGetter) {
|
|
s.Fail(fmt.Sprintf("API: %v not implementing NamespaceIDGetter", methodName))
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *namespaceSuite) TestGetNamespace() {
|
|
register := namespace.NewMockRegistry(gomock.NewController(s.T()))
|
|
register.EXPECT().GetNamespace(namespace.Name("exist")).Return(nil, nil)
|
|
register.EXPECT().GetNamespace(namespace.Name("nonexist")).Return(nil, errors.New("not found"))
|
|
register.EXPECT().GetNamespaceName(namespace.ID("exist")).Return(namespace.Name("exist"), nil)
|
|
register.EXPECT().GetNamespaceName(namespace.ID("nonexist")).Return(namespace.EmptyName, errors.New("not found"))
|
|
testCases := []struct {
|
|
method interface{}
|
|
namespaceName namespace.Name
|
|
}{
|
|
{
|
|
&workflowservice.DescribeNamespaceRequest{Namespace: "exist"},
|
|
namespace.Name("exist"),
|
|
},
|
|
{
|
|
&workflowservice.DescribeNamespaceRequest{Namespace: "nonexist"},
|
|
namespace.EmptyName,
|
|
},
|
|
{
|
|
&historyservice.DescribeMutableStateRequest{NamespaceId: "exist"},
|
|
namespace.Name("exist"),
|
|
},
|
|
{
|
|
&historyservice.DescribeMutableStateRequest{NamespaceId: "nonexist"},
|
|
namespace.EmptyName,
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
extractedNamespace := MustGetNamespaceName(register, testCase.method)
|
|
s.Equal(testCase.namespaceName, extractedNamespace)
|
|
}
|
|
}
|