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 Oct 13, 2023
1 parent c339c41 commit 0b6d4eb
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ func TestConfigEntryController_updatesEntConfigEntry(t *testing.T) {
},
updateF: func(resource common.ConfigEntryResource) {
sg := resource.(*v1alpha1.SamenessGroup)
sg.Spec.IncludeLocal = false
sg.Spec.DefaultForFailover = false
},
compare: func(t *testing.T, consulEntry capi.ConfigEntry) {
resource, ok := consulEntry.(*capi.SamenessGroupConfigEntry)
require.True(t, ok, "cast error")
require.Equal(t, true, resource.DefaultForFailover)
require.Equal(t, false, resource.IncludeLocal)
require.Equal(t, false, resource.DefaultForFailover)
require.Equal(t, true, resource.IncludeLocal)
require.Equal(t, "dc1", resource.Members[0].Peer)
require.Equal(t, "", resource.Members[0].Partition)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ func TestMeshConfigController_createsMeshConfig(t *testing.T) {
resourceClient, err := consul.NewResourceServiceClient(testClient.Watcher)
require.NoError(t, err)

require.Eventually(t, func() bool {
_, _, err := testClient.APIClient.Partitions().Read(context.Background(), constants.DefaultConsulPartition, nil)
return err == nil
}, 5*time.Second, 500*time.Millisecond)

r := c.reconciler(fakeClient, testClient.Cfg, testClient.Watcher, logrtest.New(t))
namespacedName := types.NamespacedName{
Namespace: metav1.NamespaceDefault,
Expand Down Expand Up @@ -284,6 +289,12 @@ func TestMeshConfigController_updatesMeshConfig(t *testing.T) {
})
resourceClient, err := consul.NewResourceServiceClient(testClient.Watcher)
require.NoError(t, err)

require.Eventually(t, func() bool {
_, _, err := testClient.APIClient.Partitions().Read(context.Background(), constants.DefaultConsulPartition, nil)
return err == nil
}, 5*time.Second, 500*time.Millisecond)

// We haven't run reconcile yet, so we must create the MeshConfig
// in Consul ourselves.
{
Expand Down Expand Up @@ -400,6 +411,11 @@ func TestMeshConfigController_deletesMeshConfig(t *testing.T) {
resourceClient, err := consul.NewResourceServiceClient(testClient.Watcher)
require.NoError(t, err)

require.Eventually(t, func() bool {
_, _, err := testClient.APIClient.Partitions().Read(context.Background(), constants.DefaultConsulPartition, nil)
return err == nil
}, 5*time.Second, 500*time.Millisecond)

// We haven't run reconcile yet, so we must create the config entry
// in Consul ourselves.
{
Expand Down Expand Up @@ -466,6 +482,11 @@ func TestMeshConfigController_errorUpdatesSyncStatus(t *testing.T) {
c.Experiments = []string{"resource-apis"}
})

require.Eventually(t, func() bool {
_, _, err := testClient.APIClient.Partitions().Read(context.Background(), constants.DefaultConsulPartition, nil)
return err == nil
}, 5*time.Second, 500*time.Millisecond)

// Stop the server before calling reconcile imitating a server that's not running.
_ = testClient.TestServer.Stop()

Expand Down Expand Up @@ -547,6 +568,11 @@ func TestMeshConfigController_setsSyncedToTrue(t *testing.T) {
resourceClient, err := consul.NewResourceServiceClient(testClient.Watcher)
require.NoError(t, err)

require.Eventually(t, func() bool {
_, _, err := testClient.APIClient.Partitions().Read(context.Background(), constants.DefaultConsulPartition, nil)
return err == nil
}, 5*time.Second, 500*time.Millisecond)

reconciler := &TrafficPermissionsController{
Client: fakeClient,
Log: logrtest.New(t),
Expand Down Expand Up @@ -622,6 +648,11 @@ func TestMeshConfigController_doesNotCreateUnownedMeshConfig(t *testing.T) {
resourceClient, err := consul.NewResourceServiceClient(testClient.Watcher)
require.NoError(t, err)

require.Eventually(t, func() bool {
_, _, err := testClient.APIClient.Partitions().Read(context.Background(), constants.DefaultConsulPartition, nil)
return err == nil
}, 5*time.Second, 500*time.Millisecond)

unmanagedResource := trafficpermissions.Resource(constants.DefaultConsulNS, constants.DefaultConsulPartition)
unmanagedResource.Metadata = make(map[string]string) // Zero out the metadata

Expand Down Expand Up @@ -725,6 +756,11 @@ func TestMeshConfigController_doesNotDeleteUnownedConfig(t *testing.T) {
resourceClient, err := consul.NewResourceServiceClient(testClient.Watcher)
require.NoError(t, err)

require.Eventually(t, func() bool {
_, _, err := testClient.APIClient.Partitions().Read(context.Background(), constants.DefaultConsulPartition, nil)
return err == nil
}, 5*time.Second, 500*time.Millisecond)

reconciler := &TrafficPermissionsController{
Client: fakeClient,
Log: logrtest.New(t),
Expand Down
Loading

0 comments on commit 0b6d4eb

Please sign in to comment.