From f451ada3cce01eceab423290b3ed6f2d5052ddbf Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Thu, 21 Oct 2021 23:32:59 +0200 Subject: [PATCH 1/8] topology: memory: allow encode/decode cycle (#283) After we fixed #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: https://github.com/jaypipes/ghw/issues/283 Signed-off-by: Francesco Romani --- pkg/memory/memory_test.go | 21 +++++++++++++++++++++ pkg/pci/pci_test.go | 21 +++++++++++++++++++++ pkg/topology/topology_test.go | 21 +++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/pkg/memory/memory_test.go b/pkg/memory/memory_test.go index 74da23da..cbbcc32c 100644 --- a/pkg/memory/memory_test.go +++ b/pkg/memory/memory_test.go @@ -7,10 +7,12 @@ package memory_test import ( + "encoding/json" "os" "testing" "github.com/jaypipes/ghw/pkg/memory" + "github.com/jaypipes/ghw/pkg/option" ) // nolint: gocyclo @@ -46,3 +48,22 @@ func TestMemory(t *testing.T) { t.Fatalf("Expected >0 supported page sizes, but got 0.") } } + +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) + } +} diff --git a/pkg/pci/pci_test.go b/pkg/pci/pci_test.go index 8cb7db54..fbbd3a9a 100644 --- a/pkg/pci/pci_test.go +++ b/pkg/pci/pci_test.go @@ -7,9 +7,11 @@ package pci_test import ( + "encoding/json" "os" "testing" + "github.com/jaypipes/ghw/pkg/option" "github.com/jaypipes/ghw/pkg/pci" ) @@ -58,3 +60,22 @@ func TestPCI(t *testing.T) { } } } + +func TestPCIMarshalUnmarshal(t *testing.T) { + data, err := pci.New(option.WithNullAlerter()) + if err != nil { + t.Fatalf("Expected no error creating pci.Info, but got %v", err) + } + + jdata, err := json.Marshal(data) + if err != nil { + t.Fatalf("Expected no error marshaling pci.Info, but got %v", err) + } + + var topo *pci.Info + + err = json.Unmarshal(jdata, &topo) + if err != nil { + t.Fatalf("Expected no error unmarshaling pci.Info, but got %v", err) + } +} diff --git a/pkg/topology/topology_test.go b/pkg/topology/topology_test.go index 41810ac4..a75f7dca 100644 --- a/pkg/topology/topology_test.go +++ b/pkg/topology/topology_test.go @@ -7,9 +7,11 @@ package topology_test import ( + "encoding/json" "os" "testing" + "github.com/jaypipes/ghw/pkg/option" "github.com/jaypipes/ghw/pkg/topology" ) @@ -57,3 +59,22 @@ func TestTopology(t *testing.T) { } } } + +func TestTopologyMarshalUnmarshal(t *testing.T) { + data, err := topology.New(option.WithNullAlerter()) + if err != nil { + t.Fatalf("Expected no error creating topology.Info, but got %v", err) + } + + jdata, err := json.Marshal(data) + if err != nil { + t.Fatalf("Expected no error marshaling topology.Info, but got %v", err) + } + + var topo *topology.Info + + err = json.Unmarshal(jdata, &topo) + if err != nil { + t.Fatalf("Expected no error unmarshaling topology.Info, but got %v", err) + } +} From 9dc11a8617fbade7011c3c53f5d9daf4adbf46c0 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 23 Nov 2021 08:13:28 +0100 Subject: [PATCH 2/8] ci; gh actions: remove golang 1.14 Let's begin the toolchain rotation by removing golang 1.14 from the supported set. It's just too old nowadays (november 2021). Signed-off-by: Francesco Romani --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7e035454..57c95bb2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -42,7 +42,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - go: [ '1.14', '1.15', '1.16' ] + go: [ '1.15', '1.16' ] steps: - uses: actions/checkout@v2 From c4f0797ef0fe9f961779f4e5ff96ccb143abfbd9 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 23 Nov 2021 08:14:26 +0100 Subject: [PATCH 3/8] go.mod: bump module to 1.15 The minimum version of golang we recommend and test in CI is 1.15 anyway. Signed-off-by: Francesco Romani --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0ce4b3d5..e3a8268e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/jaypipes/ghw -go 1.12 +go 1.15 require ( github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d From 56ae4f9f5580f0055f34c07ba3400607ed389068 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 23 Nov 2021 08:17:32 +0100 Subject: [PATCH 4/8] gofmt: tree: pass with golang 1.17 This PR implements the changes automatically done using ``` gofmt -s -w . ``` Signed-off-by: Francesco Romani --- cmd/ghw-snapshot/main.go | 2 ++ pkg/baseboard/baseboard_stub.go | 2 ++ pkg/bios/bios_stub.go | 2 ++ pkg/block/block_linux_test.go | 1 + pkg/block/block_stub.go | 2 ++ pkg/chassis/chassis_stub.go | 2 ++ pkg/cpu/cpu_stub.go | 2 ++ pkg/cpu/cpu_windows.go | 2 ++ pkg/gpu/gpu_stub.go | 2 ++ pkg/linuxpath/path_linux_test.go | 1 + pkg/memory/memory_stub.go | 2 ++ pkg/net/net_linux_test.go | 1 + pkg/net/net_stub.go | 2 ++ pkg/pci/pci_stub.go | 2 ++ pkg/product/product_stub.go | 2 ++ pkg/snapshot/clonetree_stub.go | 2 ++ pkg/topology/topology_stub.go | 2 ++ 17 files changed, 31 insertions(+) diff --git a/cmd/ghw-snapshot/main.go b/cmd/ghw-snapshot/main.go index efd2d5a8..20b05de1 100644 --- a/cmd/ghw-snapshot/main.go +++ b/cmd/ghw-snapshot/main.go @@ -1,4 +1,6 @@ +//go:build linux // +build linux + // // Use and distribution licensed under the Apache license version 2. // diff --git a/pkg/baseboard/baseboard_stub.go b/pkg/baseboard/baseboard_stub.go index 2c83c71c..f5b14691 100644 --- a/pkg/baseboard/baseboard_stub.go +++ b/pkg/baseboard/baseboard_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !windows // +build !linux,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/bios/bios_stub.go b/pkg/bios/bios_stub.go index 362df4c9..5307b4a0 100644 --- a/pkg/bios/bios_stub.go +++ b/pkg/bios/bios_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !windows // +build !linux,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/block/block_linux_test.go b/pkg/block/block_linux_test.go index 6b96e4cd..007076c9 100644 --- a/pkg/block/block_linux_test.go +++ b/pkg/block/block_linux_test.go @@ -4,6 +4,7 @@ // See the COPYING file in the root project directory for full text. // +//go:build linux // +build linux package block diff --git a/pkg/block/block_stub.go b/pkg/block/block_stub.go index 033725de..f5b51645 100644 --- a/pkg/block/block_stub.go +++ b/pkg/block/block_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !darwin && !windows // +build !linux,!darwin,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/chassis/chassis_stub.go b/pkg/chassis/chassis_stub.go index 2e45e15a..0e3fd94b 100644 --- a/pkg/chassis/chassis_stub.go +++ b/pkg/chassis/chassis_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !windows // +build !linux,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/cpu/cpu_stub.go b/pkg/cpu/cpu_stub.go index 9ff41cd1..5d07ee43 100644 --- a/pkg/cpu/cpu_stub.go +++ b/pkg/cpu/cpu_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !windows // +build !linux,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/cpu/cpu_windows.go b/pkg/cpu/cpu_windows.go index 07a7dddd..3de16498 100644 --- a/pkg/cpu/cpu_windows.go +++ b/pkg/cpu/cpu_windows.go @@ -1,4 +1,6 @@ +//go:build !linux // +build !linux + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/gpu/gpu_stub.go b/pkg/gpu/gpu_stub.go index 9604637d..48991ec8 100644 --- a/pkg/gpu/gpu_stub.go +++ b/pkg/gpu/gpu_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !windows // +build !linux,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/linuxpath/path_linux_test.go b/pkg/linuxpath/path_linux_test.go index e34b6019..dc0e606a 100644 --- a/pkg/linuxpath/path_linux_test.go +++ b/pkg/linuxpath/path_linux_test.go @@ -4,6 +4,7 @@ // See the COPYING file in the root project directory for full text. // +//go:build linux // +build linux package linuxpath_test diff --git a/pkg/memory/memory_stub.go b/pkg/memory/memory_stub.go index 26a28b05..6ce99e00 100644 --- a/pkg/memory/memory_stub.go +++ b/pkg/memory/memory_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !windows // +build !linux,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/net/net_linux_test.go b/pkg/net/net_linux_test.go index eaf90577..88678894 100644 --- a/pkg/net/net_linux_test.go +++ b/pkg/net/net_linux_test.go @@ -4,6 +4,7 @@ // See the COPYING file in the root project directory for full text. // +//go:build linux // +build linux package net diff --git a/pkg/net/net_stub.go b/pkg/net/net_stub.go index a19b7699..c8dfa090 100644 --- a/pkg/net/net_stub.go +++ b/pkg/net/net_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !windows // +build !linux,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/pci/pci_stub.go b/pkg/pci/pci_stub.go index 2588878c..9ebb396d 100644 --- a/pkg/pci/pci_stub.go +++ b/pkg/pci/pci_stub.go @@ -1,4 +1,6 @@ +//go:build !linux // +build !linux + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/product/product_stub.go b/pkg/product/product_stub.go index 8d848b62..8fc9724f 100644 --- a/pkg/product/product_stub.go +++ b/pkg/product/product_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !windows // +build !linux,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. diff --git a/pkg/snapshot/clonetree_stub.go b/pkg/snapshot/clonetree_stub.go index 9665875a..af85a55b 100644 --- a/pkg/snapshot/clonetree_stub.go +++ b/pkg/snapshot/clonetree_stub.go @@ -1,4 +1,6 @@ +//go:build !linux // +build !linux + // // Use and distribution licensed under the Apache license version 2. // diff --git a/pkg/topology/topology_stub.go b/pkg/topology/topology_stub.go index b2b801f7..b5ee4354 100644 --- a/pkg/topology/topology_stub.go +++ b/pkg/topology/topology_stub.go @@ -1,4 +1,6 @@ +//go:build !linux && !windows // +build !linux,!windows + // Use and distribution licensed under the Apache license version 2. // // See the COPYING file in the root project directory for full text. From 73875bba476188c3f6023c2fed6533a39159db18 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 23 Nov 2021 08:19:41 +0100 Subject: [PATCH 5/8] gh actions: move the format check to golang 1.17 Signed-off-by: Francesco Romani --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 57c95bb2..c66b22a7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,7 +19,7 @@ jobs: - name: set up golang uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.17 - name: format run: ./hack/check-format.sh From 1413194d0c42dca843b895c757b19aa6cbaf56ac Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 23 Nov 2021 08:22:23 +0100 Subject: [PATCH 6/8] test: remove stale test Remove generic test that needs to be moved in the os-specific test until the tier-2 platform (mac, win) catch up with the implementation. These tests are meant to be in the linux-specific test from the beginning, they seem to have sneaked in the generic codebase due to a rebase glitch. Signed-off-by: Francesco Romani --- pkg/memory/memory_test.go | 21 --------------------- pkg/pci/pci_test.go | 21 --------------------- pkg/topology/topology_test.go | 21 --------------------- 3 files changed, 63 deletions(-) diff --git a/pkg/memory/memory_test.go b/pkg/memory/memory_test.go index cbbcc32c..74da23da 100644 --- a/pkg/memory/memory_test.go +++ b/pkg/memory/memory_test.go @@ -7,12 +7,10 @@ package memory_test import ( - "encoding/json" "os" "testing" "github.com/jaypipes/ghw/pkg/memory" - "github.com/jaypipes/ghw/pkg/option" ) // nolint: gocyclo @@ -48,22 +46,3 @@ func TestMemory(t *testing.T) { t.Fatalf("Expected >0 supported page sizes, but got 0.") } } - -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) - } -} diff --git a/pkg/pci/pci_test.go b/pkg/pci/pci_test.go index fbbd3a9a..8cb7db54 100644 --- a/pkg/pci/pci_test.go +++ b/pkg/pci/pci_test.go @@ -7,11 +7,9 @@ package pci_test import ( - "encoding/json" "os" "testing" - "github.com/jaypipes/ghw/pkg/option" "github.com/jaypipes/ghw/pkg/pci" ) @@ -60,22 +58,3 @@ func TestPCI(t *testing.T) { } } } - -func TestPCIMarshalUnmarshal(t *testing.T) { - data, err := pci.New(option.WithNullAlerter()) - if err != nil { - t.Fatalf("Expected no error creating pci.Info, but got %v", err) - } - - jdata, err := json.Marshal(data) - if err != nil { - t.Fatalf("Expected no error marshaling pci.Info, but got %v", err) - } - - var topo *pci.Info - - err = json.Unmarshal(jdata, &topo) - if err != nil { - t.Fatalf("Expected no error unmarshaling pci.Info, but got %v", err) - } -} diff --git a/pkg/topology/topology_test.go b/pkg/topology/topology_test.go index a75f7dca..41810ac4 100644 --- a/pkg/topology/topology_test.go +++ b/pkg/topology/topology_test.go @@ -7,11 +7,9 @@ package topology_test import ( - "encoding/json" "os" "testing" - "github.com/jaypipes/ghw/pkg/option" "github.com/jaypipes/ghw/pkg/topology" ) @@ -59,22 +57,3 @@ func TestTopology(t *testing.T) { } } } - -func TestTopologyMarshalUnmarshal(t *testing.T) { - data, err := topology.New(option.WithNullAlerter()) - if err != nil { - t.Fatalf("Expected no error creating topology.Info, but got %v", err) - } - - jdata, err := json.Marshal(data) - if err != nil { - t.Fatalf("Expected no error marshaling topology.Info, but got %v", err) - } - - var topo *topology.Info - - err = json.Unmarshal(jdata, &topo) - if err != nil { - t.Fatalf("Expected no error unmarshaling topology.Info, but got %v", err) - } -} From 6a8385d94e18253cde064a41487aabd7c666715e Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 23 Nov 2021 08:24:06 +0100 Subject: [PATCH 7/8] ci: gh actions: add golang 1.17 Add golang 1.17 to our supported matrix. Signed-off-by: Francesco Romani --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c66b22a7..7ddcad4c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -42,7 +42,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - go: [ '1.15', '1.16' ] + go: [ '1.15', '1.16', '1.17' ] steps: - uses: actions/checkout@v2 From e90cb8165b2b25953ae712d4795b701b7868dc8b Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 23 Nov 2021 08:27:32 +0100 Subject: [PATCH 8/8] ci: gh actions: bump golang on mac to 1.16 We used golang 1.15 on mac only because it was the latest version available. Signed-off-by: Francesco Romani --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7ddcad4c..b260115a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -91,7 +91,7 @@ jobs: runs-on: macos-10.15 strategy: matrix: - go: [ '1.15' ] # TODO: no 1.16 atm + go: [ '1.16' ] steps: - uses: actions/checkout@v2