2023-08-11 13:12:13 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
2023-06-06 21:09:48 +00:00
|
|
|
package catalogtest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
svctest "github.com/hashicorp/consul/agent/grpc-external/services/resource/testing"
|
|
|
|
"github.com/hashicorp/consul/internal/catalog"
|
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers"
|
|
|
|
"github.com/hashicorp/consul/internal/controller"
|
|
|
|
"github.com/hashicorp/consul/internal/resource/reaper"
|
2023-11-08 15:45:25 +00:00
|
|
|
rtest "github.com/hashicorp/consul/internal/resource/resourcetest"
|
2023-06-06 21:09:48 +00:00
|
|
|
"github.com/hashicorp/consul/proto-public/pbresource"
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
|
|
|
)
|
|
|
|
|
2023-11-08 15:45:25 +00:00
|
|
|
var (
|
|
|
|
clientOpts = rtest.ConfigureTestCLIFlags()
|
|
|
|
)
|
|
|
|
|
2023-06-06 21:09:48 +00:00
|
|
|
func runInMemResourceServiceAndControllers(t *testing.T, deps controllers.Dependencies) pbresource.ResourceServiceClient {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
ctx := testutil.TestContext(t)
|
|
|
|
|
|
|
|
// Create the in-mem resource service
|
|
|
|
client := svctest.RunResourceService(t, catalog.RegisterTypes)
|
|
|
|
|
|
|
|
// Setup/Run the controller manager
|
|
|
|
mgr := controller.NewManager(client, testutil.Logger(t))
|
|
|
|
catalog.RegisterControllers(mgr, deps)
|
|
|
|
|
|
|
|
// We also depend on the reaper to take care of cleaning up owned health statuses and
|
|
|
|
// service endpoints so we must enable that controller as well
|
|
|
|
reaper.RegisterControllers(mgr)
|
|
|
|
mgr.SetRaftLeader(true)
|
|
|
|
go mgr.Run(ctx)
|
|
|
|
|
|
|
|
return client
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestControllers_Integration(t *testing.T) {
|
|
|
|
client := runInMemResourceServiceAndControllers(t, catalog.DefaultControllerDependencies())
|
2023-11-08 15:45:25 +00:00
|
|
|
RunCatalogV2Beta1IntegrationTest(t, client, clientOpts.ClientOptions(t)...)
|
2023-06-06 21:09:48 +00:00
|
|
|
}
|
2023-06-16 16:58:53 +00:00
|
|
|
|
|
|
|
func TestControllers_Lifecycle(t *testing.T) {
|
|
|
|
client := runInMemResourceServiceAndControllers(t, catalog.DefaultControllerDependencies())
|
2023-11-08 15:45:25 +00:00
|
|
|
RunCatalogV2Beta1LifecycleIntegrationTest(t, client, clientOpts.ClientOptions(t)...)
|
2023-06-16 16:58:53 +00:00
|
|
|
}
|