forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
topology: memory: allow encode/decode cycle (jaypipes#283)
After we fixed jaypipes#275 (allow marshal/unmarshal cycle for block.Info), we discovered few more occourrences which also prevented full JSON encode/decode/encode cycles (aka roundtrips). All of the new findings still see unnecessary limitations, so this patch adds the missing functions. Fixes: jaypipes#283 Signed-off-by: Francesco Romani <[email protected]>
- Loading branch information
Showing
5 changed files
with
134 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Use and distribution licensed under the Apache license version 2. | ||
// | ||
// See the COPYING file in the root project directory for full text. | ||
// | ||
|
||
package memory_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/jaypipes/ghw/pkg/memory" | ||
"github.com/jaypipes/ghw/pkg/option" | ||
) | ||
|
||
// we have this test in memory_linux_test.go (and not in memory_test.go) because `mem.load.Info` is implemented | ||
// only on linux; so having it in the platform-independent tests would lead to false negatives. | ||
func TestMemoryMarshalUnmarshal(t *testing.T) { | ||
data, err := memory.New(option.WithNullAlerter()) | ||
if err != nil { | ||
t.Fatalf("Expected no error creating memory.Info, but got %v", err) | ||
} | ||
|
||
jdata, err := json.Marshal(data) | ||
if err != nil { | ||
t.Fatalf("Expected no error marshaling memory.Info, but got %v", err) | ||
} | ||
|
||
var topo *memory.Info | ||
|
||
err = json.Unmarshal(jdata, &topo) | ||
if err != nil { | ||
t.Fatalf("Expected no error unmarshaling memory.Info, but got %v", err) | ||
} | ||
} |
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