github.com/jaypipes/ghw@v0.21.1/pkg/memory/memory_linux_test.go (about) 1 // 2 // Use and distribution licensed under the Apache license version 2. 3 // 4 // See the COPYING file in the root project directory for full text. 5 // 6 7 package memory_test 8 9 import ( 10 "encoding/json" 11 "testing" 12 13 "github.com/jaypipes/ghw/pkg/memory" 14 "github.com/jaypipes/ghw/pkg/option" 15 ) 16 17 // we have this test in memory_linux_test.go (and not in memory_test.go) because `mem.load.Info` is implemented 18 // only on linux; so having it in the platform-independent tests would lead to false negatives. 19 func TestMemoryMarshalUnmarshal(t *testing.T) { 20 data, err := memory.New(option.WithNullAlerter()) 21 if err != nil { 22 t.Fatalf("Expected no error creating memory.Info, but got %v", err) 23 } 24 25 jdata, err := json.Marshal(data) 26 if err != nil { 27 t.Fatalf("Expected no error marshaling memory.Info, but got %v", err) 28 } 29 30 var topo *memory.Info 31 32 err = json.Unmarshal(jdata, &topo) 33 if err != nil { 34 t.Fatalf("Expected no error unmarshaling memory.Info, but got %v", err) 35 } 36 }