From 2cddb4d2b9b7912299bd2ac4376b3546ff0dfcdb Mon Sep 17 00:00:00 2001 From: Maksim An Date: Wed, 6 Apr 2022 01:36:15 -0700 Subject: [PATCH] Add unit tests for mirrorBytes. Signed-off-by: Maksim An --- internal/guest/amdsev/report_test.go | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 internal/guest/amdsev/report_test.go diff --git a/internal/guest/amdsev/report_test.go b/internal/guest/amdsev/report_test.go new file mode 100644 index 0000000000..2f233031c1 --- /dev/null +++ b/internal/guest/amdsev/report_test.go @@ -0,0 +1,53 @@ +//go:build linux +// +build linux + +package amdsev + +import ( + "testing" +) + +func Test_Mirror_NonEmpty_Byte_Slices(t *testing.T) { + type config struct { + name string + input []byte + expected []byte + } + + for _, conf := range []config{ + { + name: "Length0", + input: []byte{}, + expected: []byte{}, + }, + { + name: "Length1", + input: []byte{100}, + expected: []byte{100}, + }, + { + name: "LengthOdd", + input: []byte{100, 101, 102, 103, 104}, + expected: []byte{104, 103, 102, 101, 100}, + }, + { + name: "LengthEven", + input: []byte{100, 101, 102, 103, 104, 105}, + expected: []byte{105, 104, 103, 102, 101, 100}, + }, + } { + t.Run(conf.name, func(t *testing.T) { + result := mirrorBytes(conf.input) + if string(result[:]) != string(conf.expected[:]) { + t.Fatalf("the ipnut byte array %+v was not mirrored; %+v", conf.input, result) + } + }) + } +} + +func Test_Mirror_Nil_Slice(t *testing.T) { + result := mirrorBytes(nil) + if result != nil { + t.Fatalf("expected nil slice, got: %+v", result) + } +}