Newer
Older
want []uuid.UUID
}{
{
name: "default",
want: []uuid.UUID{pending.cuid},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pnd := newPnd()
if got := pnd.PendingChanges(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("pndImplementation.PendingChanges() = %v, want %v", got, tt.want)
}
})
}
}
func Test_pndImplementation_CommittedChanges(t *testing.T) {
testName := t.Name()
callback := func(first ygot.GoStruct, second ygot.GoStruct) error {
log.Infof("callback in test %v", testName)
return nil
}
committed := NewChange(did, &openconfig.Device{}, &openconfig.Device{}, callback)
if err := committed.Commit(); err != nil {
t.Error(err)
return
}
if err := store.Add(committed); err != nil {
t.Error(err)
return
}
tests := []struct {
name string
want []uuid.UUID
}{
{
name: "default",
want: []uuid.UUID{committed.cuid},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pnd := newPnd()
if got := pnd.CommittedChanges(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("pndImplementation.CommittedChanges() = %v, want %v", got, tt.want)
}
})
}
}
func Test_pndImplementation_ConfirmedChanges(t *testing.T) {
testName := t.Name()
callback := func(first ygot.GoStruct, second ygot.GoStruct) error {
log.Infof("callback in test %v", testName)
return nil
}
confirmed := NewChange(did, &openconfig.Device{}, &openconfig.Device{}, callback)
if err := confirmed.Commit(); err != nil {
t.Error(err)
return
}
if err := confirmed.Confirm(); err != nil {
t.Error(err)
return
}
if err := store.Add(confirmed); err != nil {
t.Error(err)
return
}
tests := []struct {
name string
want []uuid.UUID
}{
{
name: "default",
want: []uuid.UUID{confirmed.cuid},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pnd := newPnd()
if got := pnd.ConfirmedChanges(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("pndImplementation.ConfirmedChanges() = %v, want %v", got, tt.want)
}
})
}
}
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
func Test_pndImplementation_saveGoStructsToFile(t *testing.T) {
type genericGoStructClientArg struct {
fn string
rtrn []interface{}
times int
}
// Create a new mock for GenericGoStructClient. With
// genericGoStructClientArg it is possible to set the Return values of the
// mocks methods.
newGenericGoStructClient := func(args ...genericGoStructClientArg) *mocks.GenericGoStructClient {
ggsc := &mocks.GenericGoStructClient{}
for _, arg := range args {
ggsc.On(arg.fn).Return(arg.rtrn...).Times(arg.times)
}
ggsc.On("CloseSend").Return(nil)
return ggsc
}
type args struct {
id uuid.UUID
client GenericGrpcClient
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "default",
args: args{
id: uuid.New(),
client: newGenericGoStructClient(
[]genericGoStructClientArg{
{
fn: "Recv",
rtrn: []interface{}{
&csbi.Payload{Chunk: []byte("test")},
nil,
},
times: 3,
},
{
fn: "Recv",
rtrn: []interface{}{
&csbi.Payload{Chunk: nil},
io.EOF,
},
times: 1,
},
}...),
},
wantErr: false,
},
{
name: "unexpected EOF error",
args: args{
id: uuid.New(),
client: newGenericGoStructClient(
[]genericGoStructClientArg{
{
fn: "Recv",
rtrn: []interface{}{
&csbi.Payload{Chunk: nil},
io.ErrUnexpectedEOF,
},
times: 1,
},
{
fn: "CloseSend",
rtrn: []interface{}{
nil,
},
times: 1,
},
}...),
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := saveGenericClientStreamToFile(tt.args.client, "gostructs.go", tt.args.id)
if (err != nil) != tt.wantErr {
t.Errorf("saveGoStructsToFile() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}