Matt Keeler 37636eab71
Catalog V2 Container Based Integration Test (#17674)
* Implement the Catalog V2 controller integration container tests

This now allows the container tests to import things from the root module. However for now we want to be very restrictive about which packages we allow importing.

* Add an upgrade test for the new catalog

Currently this should be dormant and not executed. However its put in place to detect breaking changes in the future and show an example of how to do an upgrade test with integration tests structured like catalog v2.

* Make testutil.Retry capable of performing cleanup operations

These cleanup operations are executed after each retry attempt.

* Move TestContext to taking an interface instead of a concrete testing.T

This allows this to be used on a retry.R or generally anything that meets the interface.

* Move to using TestContext instead of background contexts

Also this forces all test methods to implement the Cleanup method now instead of that being an optional interface.


Co-authored-by: Daniel Upton <daniel@floppy.co>
2023-06-16 16:29:50 -04:00

101 lines
2.4 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package cluster
import (
"context"
"io"
"github.com/testcontainers/testcontainers-go"
"google.golang.org/grpc"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/test/integration/consul-container/libs/utils"
)
// Agent represent a Consul agent abstraction
type Agent interface {
GetIP() string
GetClient() *api.Client
NewClient(string, bool) (*api.Client, error)
GetName() string
GetAgentName() string
GetPartition() string
GetPod() testcontainers.Container
Logs(context.Context) (io.ReadCloser, error)
ClaimAdminPort() (int, error)
GetConfig() Config
GetInfo() AgentInfo
GetDatacenter() string
GetNetwork() string
IsServer() bool
RegisterTermination(func() error)
Terminate() error
TerminateAndRetainPod(bool) error
Upgrade(ctx context.Context, config Config) error
Exec(ctx context.Context, cmd []string) (string, error)
DataDir() string
GetGRPCConn() *grpc.ClientConn
}
// Config is a set of configurations required to create a Agent
//
// Constructed by (Builder).ToAgentConfig()
type Config struct {
// NodeName is set for the consul agent name and container name
// Equivalent to the -node command-line flag.
// If empty, a randam name will be generated
NodeName string
// NodeID is used to configure node_id in agent config file
// Equivalent to the -node-id command-line flag.
// If empty, a randam name will be generated
NodeID string
// ExternalDataDir is data directory to copy consul data from, if set.
// This directory contains subdirectories like raft, serf, services
ExternalDataDir string
ScratchDir string
CertVolume string
CACert string
JSON string
ConfigBuilder *ConfigBuilder
Image string
Version string
Cmd []string
LogConsumer testcontainers.LogConsumer
// service defaults
UseAPIWithTLS bool // TODO
UseGRPCWithTLS bool
ACLEnabled bool
}
func (c *Config) DockerImage() string {
return utils.DockerImage(c.Image, c.Version)
}
// Clone copies everything. It is the caller's job to replace fields that
// should be unique.
func (c Config) Clone() Config {
c2 := c
if c.Cmd != nil {
c2.Cmd = make([]string, len(c.Cmd))
for i, v := range c.Cmd {
c2.Cmd[i] = v
}
}
return c2
}
// TODO: refactor away
type AgentInfo struct {
CACertFile string
UseTLSForAPI bool
UseTLSForGRPC bool
DebugURI string
}