Skip to content

Commit

Permalink
add new watch event type
Browse files Browse the repository at this point in the history
  • Loading branch information
lavalamp committed Sep 23, 2014
1 parent 8b6de5a commit 05eff2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/watch/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ const (
Added EventType = "ADDED"
Modified EventType = "MODIFIED"
Deleted EventType = "DELETED"
Error EventType = "ERROR"
)

// Event represents a single event to a watched resource.
type Event struct {
Type EventType

// If Type == Deleted, then this is the state of the object
// immediately before deletion.
// Object is:
// * If Type is Added or Modified: the new state of the object.
// * If Type is Deleted: the state of the object immediately before deletion.
// * If Type is Error: *api.Status is recommended; other types may make sense
// depending on context.
Object runtime.Object
}

Expand Down Expand Up @@ -94,6 +98,11 @@ func (f *FakeWatcher) Delete(lastValue runtime.Object) {
f.result <- Event{Deleted, lastValue}
}

// Error sends an Error event.
func (f *FakeWatcher) Error(errValue runtime.Object) {
f.result <- Event{Error, errValue}
}

// Action sends an event of the requested type, for table-based testing.
func (f *FakeWatcher) Action(action EventType, obj runtime.Object) {
f.result <- Event{action, obj}
Expand Down
2 changes: 2 additions & 0 deletions pkg/watch/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestFake(t *testing.T) {
{Modified, testType("qux")},
{Modified, testType("bar")},
{Deleted, testType("bar")},
{Error, testType("error: blah")},
}

// Prove that f implements Interface by phrasing this as a function.
Expand Down Expand Up @@ -62,6 +63,7 @@ func TestFake(t *testing.T) {
f.Action(Modified, testType("qux"))
f.Modify(testType("bar"))
f.Delete(testType("bar"))
f.Error(testType("error: blah"))
f.Stop()
}

Expand Down

0 comments on commit 05eff2e

Please sign in to comment.