Skip to content

Commit

Permalink
nonexistent test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdwhdw committed Jan 31, 2025
1 parent 015f89b commit 967f01a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions gnmi_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,41 @@ func TestGNOI(t *testing.T) {
}
})

t.Run("OSActivateNonExistentVersion", func(t *testing.T) {
mockClient := &ssc.DbusClient{}
expectedError := fmt.Errorf("Error: Image does not exist")

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

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

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

if resp.GetActivateError() == nil {
t.Fatalf("Expected ActivateError in response but got none")
}

if resp.GetActivateError().GetType() != gnoi_os_pb.ActivateError_NON_EXISTENT {
t.Errorf("Expected error type '%v' but got '%v'", gnoi_os_pb.ActivateError_NON_EXISTENT, resp.GetActivateError().GetType())
}

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

type configData struct {
source string
destination string
Expand Down

0 comments on commit 967f01a

Please sign in to comment.