| 27 | ) |
| 28 | |
| 29 | func TestJsonWriter_Event(t *testing.T) { |
| 30 | var out bytes.Buffer |
| 31 | w := &jsonWriter{ |
| 32 | out: &out, |
| 33 | dryRun: true, |
| 34 | } |
| 35 | |
| 36 | event := api.Resource{ |
| 37 | ID: "service1", |
| 38 | ParentID: "project", |
| 39 | Status: api.Working, |
| 40 | Text: api.StatusCreating, |
| 41 | Current: 50, |
| 42 | Total: 100, |
| 43 | Percent: 50, |
| 44 | } |
| 45 | w.Event(event) |
| 46 | |
| 47 | var actual jsonMessage |
| 48 | err := json.Unmarshal(out.Bytes(), &actual) |
| 49 | assert.NilError(t, err) |
| 50 | |
| 51 | expected := jsonMessage{ |
| 52 | DryRun: true, |
| 53 | ID: event.ID, |
| 54 | ParentID: event.ParentID, |
| 55 | Text: api.StatusCreating, |
| 56 | Status: "Working", |
| 57 | Current: event.Current, |
| 58 | Total: event.Total, |
| 59 | Percent: event.Percent, |
| 60 | } |
| 61 | assert.DeepEqual(t, expected, actual) |
| 62 | } |