github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/cos/fs_test.go (about)

     1  // Package cos provides common low-level types and utilities for all aistore projects
     2  /*
     3   * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package cos_test
     6  
     7  import (
     8  	"math"
     9  	"testing"
    10  
    11  	"github.com/NVIDIA/aistore/cmn/cos"
    12  	"github.com/NVIDIA/aistore/tools/tassert"
    13  	jsoniter "github.com/json-iterator/go"
    14  )
    15  
    16  func TestFsIDMarshal(t *testing.T) {
    17  	if testing.Short() {
    18  		t.Skipf("skipping %s in short mode", t.Name())
    19  	}
    20  	tests := []struct {
    21  		fsID cos.FsID
    22  	}{
    23  		{fsID: [2]int32{24, 42}},
    24  
    25  		{fsID: [2]int32{0, 1}},
    26  		{fsID: [2]int32{1, 0}},
    27  		{fsID: [2]int32{0, -1}},
    28  		{fsID: [2]int32{-1, 0}},
    29  		{fsID: [2]int32{-1, 1}},
    30  		{fsID: [2]int32{1, -1}},
    31  
    32  		{fsID: [2]int32{math.MaxInt32, math.MaxInt32}},
    33  		{fsID: [2]int32{math.MinInt32, math.MinInt32}},
    34  		{fsID: [2]int32{math.MinInt32, math.MaxInt32}},
    35  		{fsID: [2]int32{math.MaxInt32, math.MinInt32}},
    36  
    37  		{fsID: [2]int32{0, math.MinInt32}},
    38  		{fsID: [2]int32{0, math.MaxInt32}},
    39  		{fsID: [2]int32{math.MaxInt32, 0}},
    40  		{fsID: [2]int32{math.MinInt32, 0}},
    41  
    42  		{fsID: [2]int32{1, math.MinInt32}},
    43  		{fsID: [2]int32{1, math.MaxInt32}},
    44  		{fsID: [2]int32{math.MaxInt32, 1}},
    45  		{fsID: [2]int32{math.MinInt32, 1}},
    46  
    47  		{fsID: [2]int32{-1, math.MinInt32}},
    48  		{fsID: [2]int32{-1, math.MaxInt32}},
    49  		{fsID: [2]int32{math.MaxInt32, -1}},
    50  		{fsID: [2]int32{math.MinInt32, -1}},
    51  	}
    52  
    53  	for _, test := range tests {
    54  		t.Run(test.fsID.String(), func(t *testing.T) {
    55  			b, err := jsoniter.Marshal(test.fsID)
    56  			tassert.Errorf(t, err == nil, "marshal failed on input: %s, err: %v", test.fsID, err)
    57  
    58  			var tmp cos.FsID
    59  			err = jsoniter.Unmarshal(b, &tmp)
    60  			tassert.Fatalf(t, err == nil, "unmarshal failed on input: %s, err: %v", test.fsID, err)
    61  
    62  			equal := tmp[0] == test.fsID[0] && tmp[1] == test.fsID[1]
    63  			tassert.Fatalf(t, equal, "fs ids are not equal after marshal and unmarshal (expected: %s, got: %s)", test.fsID, tmp)
    64  		})
    65  	}
    66  }