Skip to content

Commit

Permalink
Create e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: khhirani <kareena.hirani@gmail.com>
  • Loading branch information
khhirani committed May 24, 2021
1 parent 465c8b1 commit f63126f
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 16 deletions.
20 changes: 8 additions & 12 deletions examples/rollout-secret.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This example demonstrates a Rollout which starts and finishes analysis at a specific canary step.
# The AnalysisTemplate references an Secret object, which contains an API, token and passes it to a Web metric provider.
# The AnalysisTemplate references an Secret object, which contains the URL, and passes it to a Web metric provider.
#
# Prerequisites: None

Expand All @@ -20,7 +20,7 @@ spec:
spec:
containers:
- name: rollouts-demo
image: argoproj/rollouts-demo:green
image: argoproj/rollouts-demo:blue
imagePullPolicy: Always
ports:
- containerPort: 8080
Expand All @@ -36,31 +36,27 @@ spec:
apiVersion: v1
kind: Secret
metadata:
name: token-secret
name: example-secret
type: Opaque
data:
# This API Token is fake. Its value decoded is "test".
apiToken: dGVzdAo=
secretUrl: aHR0cHM6Ly9naXN0LmdpdGh1YnVzZXJjb250ZW50LmNvbS9raGhpcmFuaS8yYWIxMTIzMjQwMjUxOGQ1Mjc3YWYwMzBkZDg5MTZkNy9yYXcvZDI3MmY1NTFmMmQxODA2YTAzOTc0ZGJhZWYxMWRmZDU1MTAyZmVlYS9leGFtcGxlLmpzb24=
---
kind: AnalysisTemplate
apiVersion: argoproj.io/v1alpha1
metadata:
name: analysis-secret
spec:
args:
- name: api-token
- name: secret-url
valueFrom:
secretKeyRef:
name: token-secret
key: apiToken
name: example-secret
key: secretUrl
metrics:
- name: webmetric
successCondition: result == 'It worked!'
provider:
web:
# placeholders are resolved when an AnalysisRun is created
url: "https://gist.githubusercontent.com/khhirani/2ab11232402518d5277af030dd8916d7/raw/d272f551f2d1806a03974dbaef11dfd55102feea/example.json"
headers:
- key: Test
value: "{{ args.api-token }}"
url: "{{args.secret-url}}"
jsonPath: "{$.message}"
18 changes: 14 additions & 4 deletions pkg/apis/rollouts/validation/validation_references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,18 @@ func TestValidateAnalysisMetrics(t *testing.T) {
FailureLimit: &failureLimitVal,
}}

resolvedMetrics, err := validateAnalysisMetrics(metrics, args)
assert.Nil(t, err)
assert.Equal(t, count, resolvedMetrics[0].Count.String())
assert.Equal(t, failureLimit, resolvedMetrics[0].FailureLimit.String())
t.Run("Success", func(t *testing.T) {
resolvedMetrics, err := validateAnalysisMetrics(metrics, args)
assert.Nil(t, err)
assert.Equal(t, count, resolvedMetrics[0].Count.String())
assert.Equal(t, failureLimit, resolvedMetrics[0].FailureLimit.String())
})

t.Run("Error: arg has both Value and ValueFrom", func(t *testing.T) {
args[2].Value = pointer.StringPtr("secret-value")
_, err := validateAnalysisMetrics(metrics, args)
assert.NotNil(t, err)
assert.Equal(t, "arg 'secret' has both Value and ValueFrom fields", err.Error())

})
}
21 changes: 21 additions & 0 deletions test/e2e/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,24 @@ spec:
Then().
ExpectAnalysisRunCount(1)
}

func (s *AnalysisSuite) TestAnalysisWithSecret() {
(s.Given().
RolloutObjects("@functional/rollout-secret.yaml").
When().
ApplyManifests().
WaitForRolloutStatus("Healthy").
Then().
ExpectAnalysisRunCount(0).
When().
UpdateSpec().
WaitForRolloutStatus("Paused").
Then().
ExpectAnalysisRunCount(1).
When().
WaitForInlineAnalysisRunPhase("Successful").
PromoteRollout().
WaitForRolloutStatus("Healthy").
Then().
ExpectStableRevision("2"))
}
56 changes: 56 additions & 0 deletions test/e2e/functional/rollout-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollout-secret
spec:
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
app: rollout-secret
template:
metadata:
labels:
app: rollout-secret
spec:
containers:
- name: rollouts-demo
image: argoproj/rollouts-demo:blue
imagePullPolicy: Always
ports:
- containerPort: 8080
strategy:
canary:
steps:
- setWeight: 25
- analysis:
templates:
- templateName: analysis-secret
- pause: {}
---
apiVersion: v1
kind: Secret
metadata:
name: example-secret
type: Opaque
data:
secretUrl: aHR0cHM6Ly9naXN0LmdpdGh1YnVzZXJjb250ZW50LmNvbS9raGhpcmFuaS8yYWIxMTIzMjQwMjUxOGQ1Mjc3YWYwMzBkZDg5MTZkNy9yYXcvZDI3MmY1NTFmMmQxODA2YTAzOTc0ZGJhZWYxMWRmZDU1MTAyZmVlYS9leGFtcGxlLmpzb24=
---
kind: AnalysisTemplate
apiVersion: argoproj.io/v1alpha1
metadata:
name: analysis-secret
spec:
args:
- name: secret-url
valueFrom:
secretKeyRef:
name: example-secret
key: secretUrl
metrics:
- name: webmetric
successCondition: result == 'It worked!'
provider:
web:
url: "{{args.secret-url}}"
jsonPath: "{$.message}"

0 comments on commit f63126f

Please sign in to comment.