Skip to content

Commit

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

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

Expand All @@ -2988,6 +2988,36 @@ func TestGNOI(t *testing.T) {
}
})

t.Run("OSVerifyFailureMissingCurrentImage", func(t *testing.T) {
mockClient := &ssc.DbusClient{}
expectedDbusOut := `{
"next": "next_image",
"available": ["image1", "image2"]
}`
mock := gomonkey.ApplyMethod(reflect.TypeOf(mockClient), "ListImages", func(_ *ssc.DbusClient) (string, error) {
return expectedDbusOut, nil
})
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)
}

expectedError := "current image not found"
if !strings.Contains(err.Error(), expectedError) {
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 10bd8cd

Please sign in to comment.