Skip to content

Commit

Permalink
Execute filterData only if data filter is specified. (#83)
Browse files Browse the repository at this point in the history
Fixed unit tests.

Testing Done:

1. Unit tests pass
2. Added an example sensor. It failed prior to this change. Succeeded after.

Closes #82
  • Loading branch information
shrinandj authored and magaldima committed Aug 7, 2018
1 parent ab9b1b6 commit 38548a7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
4 changes: 4 additions & 0 deletions controller/signal-filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func filterContext(expected *v1alpha1.EventContext, actual *v1alpha1.EventContex
func filterData(dataFilters []*v1alpha1.DataFilter, event *v1alpha1.Event) (bool, error) {
// TODO: use the event.Context.SchemaURL to figure out correct data format to unmarshal to
// for now, let's just use a simple map[string]interface{} for arbitrary data
if dataFilters == nil {
return true, nil
}

if event == nil {
return false, fmt.Errorf("nil event")
}
Expand Down
8 changes: 4 additions & 4 deletions controller/signal-filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ func Test_filterData(t *testing.T) {
{
name: "nil event",
args: args{dataFilters: nil, event: nil},
want: false,
wantErr: true,
want: true,
wantErr: false,
},
{
name: "unsupported content type",
args: args{dataFilters: nil, event: &v1alpha1.Event{Data: []byte("a")}},
want: false,
wantErr: true,
want: true,
wantErr: false,
},
{
name: "empty data",
Expand Down
40 changes: 40 additions & 0 deletions examples/resource-sensor-config-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
generateName: resource-example-
labels:
sensors.argoproj.io/controller-instanceid: axis
spec:
signals:
- name: config-map-create
resource:
namespace: default
group: ""
version: "v1"
kind: "ConfigMap"
filter:
prefix: my-cm
triggers:
- name: ns-workflow
resource:
namespace: default
group: argoproj.io
version: v1alpha1
kind: Workflow
source:
inline: |
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
-
container:
args:
- "hello world"
command:
- cowsay
image: "docker/whalesay:latest"
name: whalesay

0 comments on commit 38548a7

Please sign in to comment.