Skip to content

Commit

Permalink
table drive and fix server GetMachineStatus test
Browse files Browse the repository at this point in the history
  • Loading branch information
benjirewis committed Jan 3, 2025
1 parent e46aa9d commit 7f0fffd
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions robot/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func TestServer(t *testing.T) {
CloudMetadata: cloud.Metadata{},
},
},
State: robot.StateRunning,
},
&pb.ConfigStatus{Revision: "rev1"},
[]*pb.ResourceStatus{
Expand All @@ -171,6 +172,8 @@ func TestServer(t *testing.T) {
CloudMetadata: &pb.GetCloudMetadataResponse{},
},
},
pb.GetMachineStatusResponse_STATE_RUNNING,
0,
0,
},
{
Expand Down Expand Up @@ -204,6 +207,7 @@ func TestServer(t *testing.T) {
},
},
},
State: robot.StateRunning,
},
&pb.ConfigStatus{Revision: "rev1"},
[]*pb.ResourceStatus{
Expand Down Expand Up @@ -233,6 +237,8 @@ func TestServer(t *testing.T) {
),
},
},
pb.GetMachineStatusResponse_STATE_RUNNING,
0,
0,
},
{
Expand Down Expand Up @@ -340,34 +346,36 @@ func TestServer(t *testing.T) {
1,
},
} {
logger, logs := logging.NewObservedTestLogger(t)
injectRobot := &inject.Robot{}
server := server.New(injectRobot)
req := pb.GetMachineStatusRequest{}
injectRobot.LoggerFunc = func() logging.Logger {
return logger
}
injectRobot.MachineStatusFunc = func(ctx context.Context) (robot.MachineStatus, error) {
return tc.injectMachineStatus, nil
}
resp, err := server.GetMachineStatus(context.Background(), &req)
test.That(t, err, test.ShouldBeNil)
test.That(t, resp.GetConfig().GetRevision(), test.ShouldEqual, tc.expConfig.Revision)
for i, res := range resp.GetResources() {
test.That(t, res.GetName(), test.ShouldResemble, tc.expResources[i].Name)
test.That(t, res.GetState(), test.ShouldResemble, tc.expResources[i].State)
test.That(t, res.GetRevision(), test.ShouldEqual, tc.expResources[i].Revision)
}
t.Run(tc.name, func(t *testing.T) {
logger, logs := logging.NewObservedTestLogger(t)
injectRobot := &inject.Robot{}
server := server.New(injectRobot)
req := pb.GetMachineStatusRequest{}
injectRobot.LoggerFunc = func() logging.Logger {
return logger
}
injectRobot.MachineStatusFunc = func(ctx context.Context) (robot.MachineStatus, error) {
return tc.injectMachineStatus, nil
}
resp, err := server.GetMachineStatus(context.Background(), &req)
test.That(t, err, test.ShouldBeNil)
test.That(t, resp.GetConfig().GetRevision(), test.ShouldEqual, tc.expConfig.Revision)
for i, res := range resp.GetResources() {
test.That(t, res.GetName(), test.ShouldResemble, tc.expResources[i].Name)
test.That(t, res.GetState(), test.ShouldResemble, tc.expResources[i].State)
test.That(t, res.GetRevision(), test.ShouldEqual, tc.expResources[i].Revision)
}

test.That(t, resp.GetState(), test.ShouldEqual, tc.expState)
test.That(t, resp.GetState(), test.ShouldEqual, tc.expState)

const badResourceStateMsg = "resource in an unknown state"
badResourceStateCount := logs.FilterLevelExact(zapcore.ErrorLevel).FilterMessageSnippet(badResourceStateMsg).Len()
test.That(t, badResourceStateCount, test.ShouldEqual, tc.expBadResourceStateCount)
const badResourceStateMsg = "resource in an unknown state"
badResourceStateCount := logs.FilterLevelExact(zapcore.ErrorLevel).FilterMessageSnippet(badResourceStateMsg).Len()
test.That(t, badResourceStateCount, test.ShouldEqual, tc.expBadResourceStateCount)

const badMachineStateMsg = "machine in an unknown state"
badMachineStateCount := logs.FilterLevelExact(zapcore.ErrorLevel).FilterMessageSnippet(badMachineStateMsg).Len()
test.That(t, badMachineStateCount, test.ShouldEqual, tc.expBadMachineStateCount)
const badMachineStateMsg = "machine in an unknown state"
badMachineStateCount := logs.FilterLevelExact(zapcore.ErrorLevel).FilterMessageSnippet(badMachineStateMsg).Len()
test.That(t, badMachineStateCount, test.ShouldEqual, tc.expBadMachineStateCount)
})
}
})

Expand Down

0 comments on commit 7f0fffd

Please sign in to comment.