-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/pillar: make ioBundleError deepcopy-able
error types very often have private members that cannot be marshalled with `json.Marshal` we fix this by only storing the error type and the error string (err.Error()) as values in uppercase members of our own ioBundleError type log output: ``` json Unmarshal in deepCopy: json: cannot unmarshal object into Go struct field IoBundleError.IoBundleList.Error.Errors of type error ``` introduced by d1e13b8 Signed-off-by: Christoph Ostarek <christoph@zededa.com>
- Loading branch information
1 parent
69b5647
commit 2c497b7
Showing
6 changed files
with
201 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2024 Zededa, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package pubsub_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/lf-edge/eve/pkg/pillar/base" | ||
"github.com/lf-edge/eve/pkg/pillar/pubsub" | ||
"github.com/lf-edge/eve/pkg/pillar/types" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func TestDeepCopyIoBundlError(t *testing.T) { | ||
logger := logrus.StandardLogger() | ||
log := base.NewSourceLogObject(logger, "test", 1234) | ||
|
||
errs := []error{ | ||
fmt.Errorf("some error"), | ||
types.ErrOwnParent{}, | ||
types.ErrParentAssigngrpMismatch{}, | ||
types.ErrEmptyAssigngrpWithParent{}, | ||
types.ErrCycleDetected{}, | ||
types.ErrIOBundleCollision{ | ||
Collisions: []types.IOBundleCollision{{ | ||
Phylabel: "phy1", | ||
USBAddr: "usb1", | ||
USBProduct: "usbprod1", | ||
PCILong: "pcilong", | ||
Assigngrp: "assigngrp", | ||
}, | ||
}, | ||
}, | ||
} | ||
iob := types.IoBundle{ | ||
Error: types.IOBundleError{ | ||
TimeOfError: time.Time{}, | ||
}, | ||
} | ||
|
||
for _, err := range errs { | ||
iob.Error.Append(err) | ||
} | ||
output := pubsub.DeepCopy(log, iob) | ||
|
||
t.Logf("copy: %v", output) | ||
|
||
for _, err := range errs { | ||
if !iob.Error.HasError(err) { | ||
t.Fatalf("error %v missing", err) | ||
} | ||
} | ||
|
||
if !cmp.Equal(output, iob) { | ||
t.Fatalf("not equal: %s", cmp.Diff(output, iob)) | ||
} | ||
} |
Oops, something went wrong.