github.com/argoproj/argo-cd@v1.8.7/test/e2e/sync_waves_test.go (about)

     1  package e2e
     2  
     3  import (
     4  	"testing"
     5  
     6  	. "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
     7  	. "github.com/argoproj/argo-cd/test/e2e/fixture"
     8  	. "github.com/argoproj/argo-cd/test/e2e/fixture/app"
     9  
    10  	"github.com/argoproj/gitops-engine/pkg/health"
    11  	. "github.com/argoproj/gitops-engine/pkg/sync/common"
    12  )
    13  
    14  func TestFixingDegradedApp(t *testing.T) {
    15  	Given(t).
    16  		Path("sync-waves").
    17  		When().
    18  		IgnoreErrors().
    19  		Create().
    20  		And(func() {
    21  			SetResourceOverrides(map[string]ResourceOverride{
    22  				"ConfigMap": {
    23  					HealthLua: `return { status = obj.metadata.annotations and obj.metadata.annotations['health'] or 'Degraded' }`,
    24  				},
    25  			})
    26  		}).
    27  		Sync().
    28  		Then().
    29  		Expect(OperationPhaseIs(OperationFailed)).
    30  		Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
    31  		Expect(HealthIs(health.HealthStatusMissing)).
    32  		Expect(ResourceResultNumbering(1)).
    33  		Expect(ResourceSyncStatusIs("ConfigMap", "cm-1", SyncStatusCodeSynced)).
    34  		Expect(ResourceHealthIs("ConfigMap", "cm-1", health.HealthStatusDegraded)).
    35  		Expect(ResourceSyncStatusIs("ConfigMap", "cm-2", SyncStatusCodeOutOfSync)).
    36  		Expect(ResourceHealthIs("ConfigMap", "cm-2", health.HealthStatusMissing)).
    37  		When().
    38  		PatchFile("cm-1.yaml", `[{"op": "replace", "path": "/metadata/annotations/health", "value": "Healthy"}]`).
    39  		PatchFile("cm-2.yaml", `[{"op": "replace", "path": "/metadata/annotations/health", "value": "Healthy"}]`).
    40  		// need to force a refresh here
    41  		Refresh(RefreshTypeNormal).
    42  		Then().
    43  		Expect(ResourceSyncStatusIs("ConfigMap", "cm-1", SyncStatusCodeOutOfSync)).
    44  		When().
    45  		Sync().
    46  		Then().
    47  		Expect(OperationPhaseIs(OperationSucceeded)).
    48  		Expect(SyncStatusIs(SyncStatusCodeSynced)).
    49  		Expect(HealthIs(health.HealthStatusHealthy)).
    50  		Expect(ResourceResultNumbering(2)).
    51  		Expect(ResourceSyncStatusIs("ConfigMap", "cm-1", SyncStatusCodeSynced)).
    52  		Expect(ResourceHealthIs("ConfigMap", "cm-1", health.HealthStatusHealthy)).
    53  		Expect(ResourceSyncStatusIs("ConfigMap", "cm-2", SyncStatusCodeSynced)).
    54  		Expect(ResourceHealthIs("ConfigMap", "cm-2", health.HealthStatusHealthy))
    55  }
    56  
    57  func TestOneProgressingDeploymentIsSucceededAndSynced(t *testing.T) {
    58  	Given(t).
    59  		Path("one-deployment").
    60  		When().
    61  		// make this deployment get stuck in progressing due to "invalidimagename"
    62  		PatchFile("deployment.yaml", `[
    63      {
    64          "op": "replace",
    65          "path": "/spec/template/spec/containers/0/image",
    66          "value": "alpine:ops!"
    67      }
    68  ]`).
    69  		Create().
    70  		Sync().
    71  		Then().
    72  		Expect(OperationPhaseIs(OperationSucceeded)).
    73  		Expect(HealthIs(health.HealthStatusProgressing)).
    74  		Expect(SyncStatusIs(SyncStatusCodeSynced)).
    75  		Expect(ResourceResultNumbering(1))
    76  }
    77  
    78  func TestDegradedDeploymentIsSucceededAndSynced(t *testing.T) {
    79  	Given(t).
    80  		Path("one-deployment").
    81  		When().
    82  		// make this deployment get stuck in progressing due to "invalidimagename"
    83  		PatchFile("deployment.yaml", `[
    84      {
    85          "op": "replace",
    86          "path": "/spec/progressDeadlineSeconds",
    87          "value": 1
    88      },
    89      {
    90          "op": "replace",
    91          "path": "/spec/template/spec/containers/0/image",
    92          "value": "alpine:ops!"
    93      }
    94  ]`).
    95  		Create().
    96  		Sync().
    97  		Then().
    98  		Expect(OperationPhaseIs(OperationSucceeded)).
    99  		Expect(HealthIs(health.HealthStatusDegraded)).
   100  		Expect(SyncStatusIs(SyncStatusCodeSynced)).
   101  		Expect(ResourceResultNumbering(1))
   102  }