Skip to content

Commit

Permalink
[e2e] 🚚 move remaining types defined in e2e to common (DataDog#32416)
Browse files Browse the repository at this point in the history
  • Loading branch information
pducolin authored Dec 23, 2024
1 parent 6285f13 commit 6c2e98e
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 66 deletions.
6 changes: 3 additions & 3 deletions test/new-e2e/pkg/components/docker_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package components

import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclient"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclientparams"
Expand All @@ -23,10 +23,10 @@ type DockerAgent struct {
ClientOptions []agentclientparams.Option
}

var _ e2e.Initializable = (*DockerAgent)(nil)
var _ common.Initializable = (*DockerAgent)(nil)

// Init is called by e2e test Suite after the component is provisioned.
func (a *DockerAgent) Init(ctx e2e.Context) (err error) {
func (a *DockerAgent) Init(ctx common.Context) (err error) {
a.Client, err = client.NewDockerAgentClient(ctx, a.DockerAgentOutput, a.ClientOptions...)
return err
}
7 changes: 3 additions & 4 deletions test/new-e2e/pkg/components/ecs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ package components
import (
"github.com/DataDog/test-infra-definitions/components/ecs"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
clientecs "github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/ecs"
)

Expand All @@ -20,10 +19,10 @@ type ECSCluster struct {
ECSClient *clientecs.Client
}

var _ e2e.Initializable = &ECSCluster{}
var _ common.Initializable = &ECSCluster{}

// Init is called by e2e test Suite after the component is provisioned.
func (c *ECSCluster) Init(e2e.Context) error {
func (c *ECSCluster) Init(common.Context) error {

ecsClient, err := clientecs.NewClient(c.ClusterOutput.ClusterName)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions test/new-e2e/pkg/components/fakeintake.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package components

import (
"github.com/DataDog/datadog-agent/test/fakeintake/client"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"

"github.com/DataDog/test-infra-definitions/components/datadog/fakeintake"
)
Expand All @@ -19,10 +19,10 @@ type FakeIntake struct {
client *client.Client
}

var _ e2e.Initializable = &FakeIntake{}
var _ common.Initializable = &FakeIntake{}

// Init is called by e2e test Suite after the component is provisioned.
func (fi *FakeIntake) Init(e2e.Context) error {
func (fi *FakeIntake) Init(common.Context) error {
fi.client = client.NewClient(fi.URL)
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions test/new-e2e/pkg/components/kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package components
import (
"time"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"

"github.com/DataDog/test-infra-definitions/components/kubernetes"
Expand All @@ -26,10 +26,10 @@ type KubernetesCluster struct {
KubernetesClient *client.KubernetesClient
}

var _ e2e.Initializable = &KubernetesCluster{}
var _ common.Initializable = &KubernetesCluster{}

// Init is called by e2e test Suite after the component is provisioned.
func (kc *KubernetesCluster) Init(e2e.Context) error {
func (kc *KubernetesCluster) Init(common.Context) error {
config, err := clientcmd.RESTConfigFromKubeConfig([]byte(kc.KubeConfig))
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions test/new-e2e/pkg/components/remotehost.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package components

import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"

osComp "github.com/DataDog/test-infra-definitions/components/os"
Expand All @@ -18,13 +18,13 @@ type RemoteHost struct {
remote.HostOutput

*client.Host
context e2e.Context
context common.Context
}

var _ e2e.Initializable = (*RemoteHost)(nil)
var _ common.Initializable = (*RemoteHost)(nil)

// Init is called by e2e test Suite after the component is provisioned.
func (h *RemoteHost) Init(ctx e2e.Context) (err error) {
func (h *RemoteHost) Init(ctx common.Context) (err error) {
h.context = ctx
h.Host, err = client.NewHost(ctx, h.HostOutput)
return err
Expand Down
6 changes: 3 additions & 3 deletions test/new-e2e/pkg/components/remotehost_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package components

import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclient"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclientparams"
Expand All @@ -22,10 +22,10 @@ type RemoteHostAgent struct {
ClientOptions []agentclientparams.Option
}

var _ e2e.Initializable = (*RemoteHostAgent)(nil)
var _ common.Initializable = (*RemoteHostAgent)(nil)

// Init is called by e2e test Suite after the component is provisioned.
func (a *RemoteHostAgent) Init(ctx e2e.Context) (err error) {
func (a *RemoteHostAgent) Init(ctx common.Context) (err error) {
a.Client, err = client.NewHostAgentClientWithParams(ctx, a.HostAgentOutput.Host, a.ClientOptions...)
return err
}
9 changes: 5 additions & 4 deletions test/new-e2e/pkg/components/remotehost_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
package components

import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"
"github.com/DataDog/test-infra-definitions/components/docker"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"
)

// RemoteHostDocker represents an Agent running directly on a Host
Expand All @@ -18,10 +19,10 @@ type RemoteHostDocker struct {
Client *client.Docker
}

var _ e2e.Initializable = (*RemoteHostDocker)(nil)
var _ common.Initializable = (*RemoteHostDocker)(nil)

// Init is called by e2e test Suite after the component is provisioned.
func (d *RemoteHostDocker) Init(ctx e2e.Context) (err error) {
func (d *RemoteHostDocker) Init(ctx common.Context) (err error) {
d.Client, err = client.NewDocker(ctx.T(), d.ManagerOutput)
return err
}
5 changes: 3 additions & 2 deletions test/new-e2e/pkg/e2e/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner/parameters"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/infra"

"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -352,7 +353,7 @@ func (bs *BaseSuite[Env]) reconcileEnv(targetProvisioners provisioners.Provision
}

// If env implements Initializable, we call Init
if initializable, ok := any(newEnv).(Initializable); ok {
if initializable, ok := any(newEnv).(common.Initializable); ok {
if err := initializable.Init(bs); err != nil {
return fmt.Errorf("failed to init environment, err: %v", err)
}
Expand Down Expand Up @@ -447,7 +448,7 @@ func (bs *BaseSuite[Env]) buildEnvFromResources(resources provisioners.RawResour
}

// See if the component requires init
if initializable, ok := fieldValue.Interface().(Initializable); ok {
if initializable, ok := fieldValue.Interface().(common.Initializable); ok {
if err := initializable.Init(bs); err != nil {
return fmt.Errorf("failed to init resource named: %s with key: %s, err: %w", field.Name, resourceKey, err)
}
Expand Down
5 changes: 3 additions & 2 deletions test/new-e2e/pkg/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
)

type testTypeOutput struct {
Expand All @@ -30,9 +31,9 @@ type testTypeWrapper struct {
unrelatedField string //nolint:unused // mimic actual struct to validate reflection code
}

var _ Initializable = &testTypeWrapper{}
var _ common.Initializable = &testTypeWrapper{}

func (t *testTypeWrapper) Init(Context) error {
func (t *testTypeWrapper) Init(common.Context) error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions test/new-e2e/pkg/environments/dockerhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package environments

import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
)

// DockerHost is an environment that contains a Docker VM, FakeIntake and Agent configured to talk to each other.
Expand All @@ -19,9 +19,9 @@ type DockerHost struct {
Docker *components.RemoteHostDocker
}

var _ e2e.Initializable = &DockerHost{}
var _ common.Initializable = &DockerHost{}

// Init initializes the environment
func (e *DockerHost) Init(_ e2e.Context) error {
func (e *DockerHost) Init(_ common.Context) error {
return nil
}
6 changes: 3 additions & 3 deletions test/new-e2e/pkg/environments/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package environments

import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
)

// Host is an environment that contains a Host, FakeIntake and Agent configured to talk to each other.
Expand All @@ -18,9 +18,9 @@ type Host struct {
Updater *components.RemoteHostUpdater
}

var _ e2e.Initializable = (*Host)(nil)
var _ common.Initializable = (*Host)(nil)

// Init initializes the environment
func (e *Host) Init(_ e2e.Context) error {
func (e *Host) Init(_ common.Context) error {
return nil
}
9 changes: 5 additions & 4 deletions test/new-e2e/pkg/environments/host_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
package environments

import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/test-infra-definitions/common/config"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
)

// WindowsHost is an environment based on environments.Host but that is specific to Windows.
Expand All @@ -22,9 +23,9 @@ type WindowsHost struct {
Installer *components.RemoteDatadogInstaller
}

var _ e2e.Initializable = &WindowsHost{}
var _ common.Initializable = &WindowsHost{}

// Init initializes the environment
func (e *WindowsHost) Init(_ e2e.Context) error {
func (e *WindowsHost) Init(_ common.Context) error {
return nil
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
// Copyright 2024-present Datadog, Inc.

package e2e
package common

import (
"testing"
)
import "testing"

// Context defines an interface that allows to get information about current test context
type Context interface {
Expand All @@ -18,13 +16,3 @@ type Context interface {
type Initializable interface {
Init(Context) error
}

// RawResources is the common types returned by provisioners
type RawResources map[string][]byte

// Merge merges two RawResources maps
func (rr RawResources) Merge(in RawResources) {
for k, v := range in {
rr[k] = v
}
}
7 changes: 4 additions & 3 deletions test/new-e2e/pkg/utils/e2e/client/agent_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclient"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclientparams"
)
Expand All @@ -29,7 +30,7 @@ const (
)

// NewHostAgentClient creates an Agent client for host install
func NewHostAgentClient(context e2e.Context, hostOutput remote.HostOutput, waitForAgentReady bool) (agentclient.Agent, error) {
func NewHostAgentClient(context common.Context, hostOutput remote.HostOutput, waitForAgentReady bool) (agentclient.Agent, error) {
params := agentclientparams.NewParams(hostOutput.OSFamily)
params.ShouldWaitForReady = waitForAgentReady

Expand All @@ -51,7 +52,7 @@ func NewHostAgentClient(context e2e.Context, hostOutput remote.HostOutput, waitF
}

// NewHostAgentClientWithParams creates an Agent client for host install with custom parameters
func NewHostAgentClientWithParams(context e2e.Context, hostOutput remote.HostOutput, options ...agentclientparams.Option) (agentclient.Agent, error) {
func NewHostAgentClientWithParams(context common.Context, hostOutput remote.HostOutput, options ...agentclientparams.Option) (agentclient.Agent, error) {
params := agentclientparams.NewParams(hostOutput.OSFamily, options...)

host, err := NewHost(context, hostOutput)
Expand All @@ -74,7 +75,7 @@ func NewHostAgentClientWithParams(context e2e.Context, hostOutput remote.HostOut
}

// NewDockerAgentClient creates an Agent client for a Docker install
func NewDockerAgentClient(context e2e.Context, dockerAgentOutput agent.DockerAgentOutput, options ...agentclientparams.Option) (agentclient.Agent, error) {
func NewDockerAgentClient(context common.Context, dockerAgentOutput agent.DockerAgentOutput, options ...agentclientparams.Option) (agentclient.Agent, error) {
params := agentclientparams.NewParams(dockerAgentOutput.DockerManager.Host.OSFamily, options...)
ae := newAgentDockerExecutor(context, dockerAgentOutput)
commandRunner := newAgentCommandRunner(context.T(), ae)
Expand Down
5 changes: 3 additions & 2 deletions test/new-e2e/pkg/utils/e2e/client/agent_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
package client

import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/test-infra-definitions/components/datadog/agent"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
)

type agentDockerExecutor struct {
Expand All @@ -17,7 +18,7 @@ type agentDockerExecutor struct {

var _ agentCommandExecutor = &agentDockerExecutor{}

func newAgentDockerExecutor(context e2e.Context, dockerAgentOutput agent.DockerAgentOutput) *agentDockerExecutor {
func newAgentDockerExecutor(context common.Context, dockerAgentOutput agent.DockerAgentOutput) *agentDockerExecutor {
dockerClient, err := NewDocker(context.T(), dockerAgentOutput.DockerManager)
if err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions test/new-e2e/pkg/utils/e2e/client/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"golang.org/x/crypto/ssh"

"github.com/DataDog/datadog-agent/pkg/util/scrubber"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner/parameters"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/common"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/optional"
)

Expand All @@ -48,7 +48,7 @@ type convertPathSeparatorFn func(string) string
type Host struct {
client *ssh.Client

context e2e.Context
context common.Context
username string
host string
privateKey []byte
Expand All @@ -63,7 +63,7 @@ type Host struct {

// NewHost creates a new ssh client to connect to a remote host with
// reconnect retry logic
func NewHost(context e2e.Context, hostOutput remote.HostOutput) (*Host, error) {
func NewHost(context common.Context, hostOutput remote.HostOutput) (*Host, error) {
var privateSSHKey []byte

privateKeyPath, err := runner.GetProfile().ParamStore().GetWithDefault(parameters.StoreKey(hostOutput.CloudProvider+parameters.PrivateKeyPathSuffix), "")
Expand Down
Loading

0 comments on commit 6c2e98e

Please sign in to comment.