Skip to content

Commit

Permalink
add more unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdwhdw committed Jan 28, 2025
1 parent e951e34 commit 1b48f45
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions gnmi_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2961,6 +2961,33 @@ func TestGNOI(t *testing.T) {
}
})

t.Run("OSVerifyFailure", func(t *testing.T) {
mockClient := &ssc.DbusClient{}
expectedError := fmt.Errorf("failed to verify OS")

mock := gomonkey.ApplyMethod(reflect.TypeOf(mockClient), "ListImages", func(_ *ssc.DbusClient) (string, error) {
return "", expectedError
})
defer mock.Reset()

// Prepare context and request
ctx := context.Background()
req := &gnoi_os_pb.VerifyRequest{}
osc := gnoi_os_pb.NewOSClient(conn)

resp, err := osc.Verify(ctx, req)
if err == nil {
t.Fatalf("Expected error but got none")
}
if resp != nil {
t.Fatalf("Expected nil response but got: %v", resp)
}

if !strings.Contains(err.Error(), expectedError.Error()) {
t.Errorf("Expected error to contain '%v' but got '%v'", expectedError, err)
}
})

type configData struct {
source string
destination string
Expand Down

0 comments on commit 1b48f45

Please sign in to comment.