-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix floatation of error/message in the backup/restore result
Signed-off-by: Shashank Singh <[email protected]>
- Loading branch information
1 parent
4d21e29
commit d473898
Showing
2 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package logging | ||
|
||
import ( | ||
"reflect" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"github.com/vmware-tanzu/velero/pkg/util/results" | ||
) | ||
|
||
type fields struct { | ||
mu sync.RWMutex | ||
counts map[logrus.Level]int | ||
entries map[logrus.Level]*results.Result | ||
} | ||
|
||
func TestLogHook_Fire(t *testing.T) { | ||
type args struct { | ||
entry *logrus.Entry | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "test", | ||
fields: fields{ | ||
mu: sync.RWMutex{}, | ||
counts: map[logrus.Level]int{ | ||
logrus.ErrorLevel: 1, | ||
}, | ||
entries: map[logrus.Level]*results.Result{ | ||
logrus.ErrorLevel: { | ||
Velero: []string{"test error"}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
entry: &logrus.Entry{ | ||
Level: logrus.ErrorLevel, | ||
Data: map[string]interface{}{ | ||
"namespace": "test", | ||
"error": errors.New("test error"), | ||
}, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
h := &LogHook{ | ||
mu: tt.fields.mu, | ||
counts: tt.fields.counts, | ||
entries: tt.fields.entries, | ||
} | ||
if err := h.Fire(tt.args.entry); (err != nil) != tt.wantErr { | ||
t.Errorf("LogHook.Fire() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestLogHook_GetCount(t *testing.T) { | ||
type args struct { | ||
level logrus.Level | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want int | ||
}{ | ||
{ | ||
name: "test", | ||
fields: fields{ | ||
mu: sync.RWMutex{}, | ||
counts: map[logrus.Level]int{ | ||
logrus.ErrorLevel: 1, | ||
}, | ||
entries: map[logrus.Level]*results.Result{ | ||
logrus.ErrorLevel: { | ||
Velero: []string{"test error"}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
level: logrus.ErrorLevel, | ||
}, | ||
want: 1, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
h := &LogHook{ | ||
mu: tt.fields.mu, | ||
counts: tt.fields.counts, | ||
entries: tt.fields.entries, | ||
} | ||
if got := h.GetCount(tt.args.level); got != tt.want { | ||
t.Errorf("LogHook.GetCount() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestLogHook_GetEntries(t *testing.T) { | ||
type args struct { | ||
level logrus.Level | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want results.Result | ||
}{ | ||
{ | ||
name: "test", | ||
fields: fields{ | ||
mu: sync.RWMutex{}, | ||
counts: map[logrus.Level]int{ | ||
logrus.ErrorLevel: 1, | ||
}, | ||
entries: map[logrus.Level]*results.Result{ | ||
logrus.ErrorLevel: { | ||
Velero: []string{"test error"}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
level: logrus.ErrorLevel, | ||
}, | ||
want: results.Result{ | ||
Velero: []string{"test error"}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
h := &LogHook{ | ||
mu: tt.fields.mu, | ||
counts: tt.fields.counts, | ||
entries: tt.fields.entries, | ||
} | ||
if got := h.GetEntries(tt.args.level); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("LogHook.GetEntries() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |