github.com/rootless-containers/rootlesskit/v2@v2.3.4/pkg/lowlevelmsgutil/lowlevelmsgutil_test.go (about)

     1  package lowlevelmsgutil
     2  
     3  import (
     4  	"encoding/hex"
     5  	"testing"
     6  )
     7  
     8  func TestMarshal(t *testing.T) {
     9  	emptyStruct := struct{}{}
    10  	fooStruct := struct{ Foo string }{Foo: "hello"}
    11  	testCases := []struct {
    12  		x interface{}
    13  	}{
    14  		{
    15  			x: nil,
    16  		},
    17  		{
    18  			x: 42,
    19  		},
    20  		{
    21  			x: &emptyStruct,
    22  		},
    23  		{
    24  			x: &fooStruct,
    25  		},
    26  	}
    27  	for i, tc := range testCases {
    28  		b, err := Marshal(tc.x)
    29  		if err != nil {
    30  			t.Fatal(err)
    31  		}
    32  		t.Logf("%d: marshal %+v\n%s", i, tc.x, hex.Dump(b))
    33  	}
    34  }