Skip to content

Commit 1d1b7ea

Browse files
simplify test struct and set proper default for oplog replay
1 parent ae4af05 commit 1d1b7ea

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

cmd/pbm-agent/oplog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (a *Agent) OplogReplay(ctx context.Context, r *ctrl.ReplayCmd, opID ctrl.OP
7777
}
7878

7979
l.Info("oplog replay started")
80-
rr := restore.New(a.leadConn, a.nodeConn, a.brief, cfg, r.RSMap, 0, 0)
80+
rr := restore.New(a.leadConn, a.nodeConn, a.brief, cfg, r.RSMap, 0, 1)
8181
err = rr.ReplayOplog(ctx, r, opID, l)
8282
if err != nil {
8383
if errors.Is(err, restore.ErrNoDataForShard) {

cmd/pbm/restore_test.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,48 +103,38 @@ func TestCloningValidation(t *testing.T) {
103103
}
104104
}
105105

106-
func Test_parseCLINumInsertionWorkersOption(t *testing.T) {
107-
108-
type args struct {
109-
value int32
110-
}
106+
func TestParseCLINumInsertionWorkersOption(t *testing.T) {
111107

112108
var num int32 = 1
113109

114110
tests := []struct {
115111
name string
116-
args args
112+
value int32
117113
want *int32
118114
wantErr bool
119115
}{
120116
{
121-
name: "valid number - no error",
122-
args: args{
123-
value: 1,
124-
},
117+
name: "valid number - no error",
118+
value: 1,
125119
want: &num,
126120
wantErr: false,
127121
},
128122
{
129-
name: "zero - no error, but return nil",
130-
args: args{
131-
value: 0,
132-
},
123+
name: "zero - no error, but return nil",
124+
value: 0,
133125
want: nil,
134126
wantErr: false,
135127
},
136128
{
137-
name: "negative value - error",
138-
args: args{
139-
value: -1,
140-
},
129+
name: "negative value - error",
130+
value: -1,
141131
want: nil,
142132
wantErr: true,
143133
},
144134
}
145135
for _, tt := range tests {
146136
t.Run(tt.name, func(t *testing.T) {
147-
got, err := parseCLINumInsertionWorkersOption(tt.args.value)
137+
got, err := parseCLINumInsertionWorkersOption(tt.value)
148138
if (err != nil) != tt.wantErr {
149139
t.Errorf("parseCLINumInsertionWorkersOption() error = %v, wantErr %v", err, tt.wantErr)
150140
return

pbm/topo/cluster.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package topo
22

33
import (
44
"context"
5-
"encoding/json"
6-
"fmt"
75
"strings"
86

97
"go.mongodb.org/mongo-driver/bson"
@@ -60,13 +58,7 @@ func GetClusterTime(ctx context.Context, m connect.Client) (primitive.Timestamp,
6058

6159
func ClusterTimeFromNodeInfo(info *NodeInfo) (primitive.Timestamp, error) {
6260
if info.ClusterTime == nil {
63-
jsonResponse, err := json.Marshal(info)
64-
errDetails := string(jsonResponse)
65-
if err != nil {
66-
fmt.Println(err)
67-
errDetails = "Unable to parse response."
68-
}
69-
return primitive.Timestamp{}, errors.Errorf("No clusterTime in response. Received: %s", errDetails)
61+
return primitive.Timestamp{}, errors.Errorf("No clusterTime in response. Received: %+v", info)
7062
}
7163

7264
return info.ClusterTime.ClusterTime, nil

0 commit comments

Comments
 (0)