Skip to content

Commit

Permalink
Fix ENT Tests Now that They Are Running Again 🏃 (#3077)
Browse files Browse the repository at this point in the history
test: fix tests that are failing on main
  • Loading branch information
DanStough authored and nathancoleman committed Oct 16, 2023
1 parent 7d0a40e commit 13bb996
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -652,6 +655,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -713,6 +719,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -725,6 +734,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-different-consul-svc-name-sidecar-proxy",
Expand Down Expand Up @@ -794,6 +806,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -806,6 +821,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -876,6 +894,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -888,6 +909,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand All @@ -905,6 +929,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-service-updated",
Service: "service-updated",
Expand All @@ -917,6 +944,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -979,6 +1009,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -991,6 +1024,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-different-consul-svc-name-sidecar-proxy",
Expand All @@ -1008,6 +1044,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -1020,6 +1059,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-different-consul-svc-name-sidecar-proxy",
Expand Down Expand Up @@ -1068,6 +1110,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -1080,6 +1125,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand All @@ -1097,6 +1145,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-service-updated",
Service: "service-updated",
Expand All @@ -1109,6 +1160,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -1145,6 +1199,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -1157,6 +1214,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-different-consul-svc-name-sidecar-proxy",
Expand All @@ -1174,6 +1234,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -1186,6 +1249,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-different-consul-svc-name-sidecar-proxy",
Expand Down Expand Up @@ -1235,6 +1301,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -1253,6 +1322,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -1321,6 +1393,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -1339,6 +1414,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand All @@ -1362,6 +1440,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-service-updated",
Service: "service-updated",
Expand All @@ -1380,6 +1461,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -1435,8 +1519,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
c.ACL.Tokens.InitialManagement = adminToken
}
})

consulClient := testClient.APIClient
// Coincidentally, this allows enough time for the bootstrap token to be generated
testClient.TestServer.WaitForActiveCARoot(t)

_, err := namespaces.EnsureExists(consulClient, ts.ExpConsulNS, "")
require.NoError(t, err)
Expand Down Expand Up @@ -1741,6 +1826,8 @@ func TestReconcileDeleteEndpointWithNamespaces(t *testing.T) {
}
})
consulClient := testClient.APIClient
// Coincidentally, this allows enough time for the bootstrap token to be generated
testClient.TestServer.WaitForActiveCARoot(t)

_, err := namespaces.EnsureExists(consulClient, ts.ExpConsulNS, "")
require.NoError(t, err)
Expand All @@ -1752,6 +1839,9 @@ func TestReconcileDeleteEndpointWithNamespaces(t *testing.T) {
Node: consulNodeName,
Address: consulNodeAddress,
Service: svc,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
}
_, err = consulClient.Catalog().Register(serviceRegistration, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -2033,6 +2123,8 @@ func TestReconcileDeleteGatewayWithNamespaces(t *testing.T) {
}
})
consulClient := testClient.APIClient
// Coincidentally, this allows enough time for the bootstrap token to be generated
testClient.TestServer.WaitForActiveCARoot(t)

_, err := namespaces.EnsureExists(consulClient, ts.ConsulNS, "")
require.NoError(t, err)
Expand All @@ -2044,6 +2136,9 @@ func TestReconcileDeleteGatewayWithNamespaces(t *testing.T) {
Node: consulNodeName,
Address: consulNodeAddress,
Service: svc,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
}
_, err = consulClient.Catalog().Register(serviceRegistration, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -2106,8 +2201,15 @@ func TestReconcileDeleteGatewayWithNamespaces(t *testing.T) {
require.Empty(t, append(defaultNS, testNS...))

if tt.enableACLs {
_, _, err = consulClient.ACL().TokenRead(token.AccessorID, nil)
require.Contains(t, err.Error(), "ACL not found")
queryOpts := &api.QueryOptions{}
if tt.initialConsulSvcs[0].Kind == api.ServiceKindMeshGateway {
queryOpts.Namespace = "default" // Mesh Gateways must always be registered in the "default" namespace.
} else {
queryOpts.Namespace = ts.ConsulNS
}

token, _, err = consulClient.ACL().TokenRead(token.AccessorID, queryOpts)
require.Contains(t, err.Error(), "ACL not found", token)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4168,6 +4168,7 @@ func TestReconcileDeleteEndpoint(t *testing.T) {
}
})
consulClient := testClient.APIClient
// TODO: stabilize this test by waiting for the ACL bootstrap

// Register service and proxy in consul
var token *api.ACLToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import (
"time"

logrtest "github.com/go-logr/logr/testr"
"github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1"
"github.com/hashicorp/consul-k8s/control-plane/connect-inject/constants"
"github.com/hashicorp/consul-k8s/control-plane/helper/test"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/stretchr/testify/require"
Expand All @@ -26,6 +23,10 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1"
"github.com/hashicorp/consul-k8s/control-plane/connect-inject/constants"
"github.com/hashicorp/consul-k8s/control-plane/helper/test"
)

// TestReconcile_CreateUpdatePeeringAcceptor creates a peering acceptor.
Expand Down Expand Up @@ -508,6 +509,7 @@ func TestReconcile_CreateUpdatePeeringAcceptor(t *testing.T) {
// Create test consul server.
testClient := test.TestServerWithMockConnMgrWatcher(t, nil)
consulClient := testClient.APIClient
testClient.TestServer.WaitForActiveCARoot(t)

if tt.initialConsulPeerName != "" {
// Add the initial peerings into Consul by calling the Generate token endpoint.
Expand Down Expand Up @@ -631,6 +633,7 @@ func TestReconcile_DeletePeeringAcceptor(t *testing.T) {
// Create test consul server.
testClient := test.TestServerWithMockConnMgrWatcher(t, nil)
consulClient := testClient.APIClient
testClient.TestServer.WaitForActiveCARoot(t)

// Add the initial peerings into Consul by calling the Generate token endpoint.
_, _, err := consulClient.Peerings().GenerateToken(context.Background(), api.PeeringGenerateTokenRequest{PeerName: "acceptor-deleted"}, nil)
Expand Down Expand Up @@ -777,6 +780,7 @@ func TestReconcile_VersionAnnotation(t *testing.T) {
// Create test consul server.
testClient := test.TestServerWithMockConnMgrWatcher(t, nil)
consulClient := testClient.APIClient
testClient.TestServer.WaitForActiveCARoot(t)

_, _, err := consulClient.Peerings().GenerateToken(context.Background(), api.PeeringGenerateTokenRequest{PeerName: "acceptor-created"}, nil)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 13bb996

Please sign in to comment.