Skip to content

Commit

Permalink
Merge 26cc1f4 into af7823b
Browse files Browse the repository at this point in the history
  • Loading branch information
bpineau committed Apr 20, 2018
2 parents af7823b + 26cc1f4 commit a8aeedd
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (c *Controller) processItem(key string) error {

if !exists {
// deleted object
c.enqueue(&event.Notification{Action: event.Delete, Key: key, Kind: c.name, Object: ""})
c.enqueue(&event.Notification{Action: event.Delete, Key: key, Kind: c.name, Object: nil})
return nil
}

Expand All @@ -207,7 +207,7 @@ func (c *Controller) processItem(key string) error {
return fmt.Errorf("failed to marshal %s: %v", key, err)
}

c.enqueue(&event.Notification{Action: event.Upsert, Key: key, Kind: c.name, Object: string(yml)})
c.enqueue(&event.Notification{Action: event.Upsert, Key: key, Kind: c.name, Object: yml})
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestController(t *testing.T) {
gotFoo2 := false
for _, ev := range evt.evts {
// ensure cleanup filters works as expected
if strings.Contains(ev.Object, "shouldnotbethere") {
if strings.Contains(string(ev.Object), "shouldnotbethere") {
t.Error("object cleanup filters didn't work")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Notification struct {
Action Action
Key string
Kind string
Object string
Object []byte
}

// Notifier mediates notifications between controllers and recorder
Expand Down
2 changes: 1 addition & 1 deletion pkg/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
Action: Upsert,
Key: "foo",
Kind: "bar",
Object: "spam egg",
Object: []byte("spam egg"),
}
)

Expand Down
13 changes: 2 additions & 11 deletions pkg/recorder/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (w *Listener) relativePath(file string) string {
return strings.Replace(file, root+"/", "", 1)
}

func (w *Listener) save(file string, data string) error {
func (w *Listener) save(file string, data []byte) error {
w.config.Logger.Debugf("Saving %s to disk", file)

if w.config.DryRun {
Expand All @@ -144,21 +144,12 @@ func (w *Listener) save(file string, data string) error {
w.actives[w.relativePath(file)] = true
w.activesLock.Unlock()

f, err := appFs.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return fmt.Errorf("failed to create %s on disk: %v", file, err)
}
err = afero.WriteFile(appFs, file, data, 0600)

_, err = f.WriteString(data)
if err != nil {
return fmt.Errorf("failed to write to %s on disk: %v", file, err)
}

err = f.Close()
if err != nil {
return fmt.Errorf("failed to close %s file: %v", file, err)
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/recorder/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newNotif(action event.Action, key string) *event.Notification {
Action: action,
Key: key,
Kind: "foo",
Object: "bar",
Object: []byte("bar"),
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func TestFailingFSRecorder(t *testing.T) {
// switching to failing (read-only) filesystem
appFs = afero.NewReadOnlyFs(appFs)

err := rec.save("foo", "bar")
err := rec.save("foo", []byte("bar"))
if err == nil {
t.Error("save should return an error in case of failure")
}
Expand Down

0 comments on commit a8aeedd

Please sign in to comment.