Skip to content

Commit

Permalink
Add more end-to-end Mixer tests. (istio#4076)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozevren authored Mar 11, 2018
1 parent 01d3f24 commit 7db319c
Showing 1 changed file with 140 additions and 13 deletions.
153 changes: 140 additions & 13 deletions mixer/test/e2e/e2e_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ spec:
value_type: INT64
---
`
reportSvcCfg = `
)

func TestReport(t *testing.T) {
tests := []testData{

{
name: "Basic Report",
cfg: `
apiVersion: "config.istio.io/v1alpha2"
kind: fakeHandler
metadata:
Expand Down Expand Up @@ -84,20 +91,94 @@ spec:
- reportInstance.samplereport
---
`
)
`,
attrs: map[string]interface{}{
"target.name": "somesrvcname",
},

expectSetTypes: map[string]interface{}{
"reportInstance.samplereport.istio-system": &reportTmpl.Type{
Value: pb.INT64,
Dimensions: map[string]pb.ValueType{"source": pb.STRING, "target_ip": pb.STRING},
},
},

expectCalls: []spyAdapter.CapturedCall{
{
Name: "HandleSampleReport",
Instances: []interface{}{
&reportTmpl.Instance{
Name: "reportInstance.samplereport.istio-system",
Value: int64(2),
Dimensions: map[string]interface{}{"source": "mysrc", "target_ip": "somesrvcname"},
},
},
},
},
},

func TestReport(t *testing.T) {
tests := []testData{
{
name: "Basic Report",
name: "Multi Instance Report",
cfg: `
apiVersion: "config.istio.io/v1alpha2"
kind: fakeHandler
metadata:
name: fakeHandlerConfig
namespace: istio-system
---
# Instance 1
apiVersion: "config.istio.io/v1alpha2"
kind: samplereport
metadata:
name: reportInstance1
namespace: istio-system
spec:
value: "2"
dimensions:
source: source.name | "mysrc"
target_ip: target.name | "mytarget"
---
# Instance 2
apiVersion: "config.istio.io/v1alpha2"
kind: samplereport
metadata:
name: reportInstance2
namespace: istio-system
spec:
value: "5"
dimensions:
source: source.name | "yoursrc"
target_ip: target.name | "yourtarget"
---
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rule1
namespace: istio-system
spec:
selector: match(target.name, "*")
actions:
- handler: fakeHandlerConfig.fakeHandler
instances:
- reportInstance1.samplereport
- reportInstance2.samplereport
---
`,
attrs: map[string]interface{}{
"target.name": "somesrvcname",
},

expectSetTypes: map[string]interface{}{
"reportInstance.samplereport.istio-system": &reportTmpl.Type{
"reportInstance1.samplereport.istio-system": &reportTmpl.Type{
Value: pb.INT64,
Dimensions: map[string]pb.ValueType{"source": pb.STRING, "target_ip": pb.STRING},
},
"reportInstance2.samplereport.istio-system": &reportTmpl.Type{
Value: pb.INT64,
Dimensions: map[string]pb.ValueType{"source": pb.STRING, "target_ip": pb.STRING},
},
Expand All @@ -108,21 +189,67 @@ func TestReport(t *testing.T) {
Name: "HandleSampleReport",
Instances: []interface{}{
&reportTmpl.Instance{
Name: "reportInstance.samplereport.istio-system",
Name: "reportInstance1.samplereport.istio-system",
Value: int64(2),
Dimensions: map[string]interface{}{"source": "mysrc", "target_ip": "somesrvcname"},
},
&reportTmpl.Instance{
Name: "reportInstance2.samplereport.istio-system",
Value: int64(5),
Dimensions: map[string]interface{}{"source": "yoursrc", "target_ip": "somesrvcname"},
},
},
},
},
},

{
name: "Conditional Report with No Success",
cfg: `
apiVersion: "config.istio.io/v1alpha2"
kind: fakeHandler
metadata:
name: fakeHandlerConfig
namespace: istio-system
---
apiVersion: "config.istio.io/v1alpha2"
kind: samplereport
metadata:
name: reportInstance
namespace: istio-system
spec:
value: "2"
dimensions:
source: source.name | "mysrc"
target_ip: target.name | "mytarget"
---
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rule1
namespace: istio-system
spec:
selector: match(target.name, "some unknown thing")
actions:
- handler: fakeHandlerConfig.fakeHandler
instances:
- reportInstance.samplereport
---
`,
attrs: map[string]interface{}{
"target.name": "somesrvcname",
},

expectCalls: nil,
},
}
for _, tt := range tests {
// Set the defaults for the test.
if tt.cfg == "" {
tt.cfg = reportSvcCfg
}

for _, tt := range tests {
if tt.templates == nil {
tt.templates = e2eTmpl.SupportedTmplInfo
}
Expand Down

0 comments on commit 7db319c

Please sign in to comment.