mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
change fs.json format to include checksum fields (#5685)
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -111,7 +112,47 @@ func TestWriteFSMetadata(t *testing.T) {
|
||||
if fsMeta.Version != fsMetaVersion {
|
||||
t.Fatalf("Unexpected version %s", fsMeta.Version)
|
||||
}
|
||||
if fsMeta.Format != fsMetaFormat {
|
||||
t.Fatalf("Unexpected format %s", fsMeta.Format)
|
||||
}
|
||||
|
||||
func TestFSChecksumV1MarshalJSON(t *testing.T) {
|
||||
var cs FSChecksumInfoV1
|
||||
|
||||
testCases := []struct {
|
||||
checksum FSChecksumInfoV1
|
||||
expectedResult string
|
||||
}{
|
||||
{cs, `{"algorithm":"","blocksize":0,"hashes":null}`},
|
||||
{FSChecksumInfoV1{Algorithm: "highwayhash", Blocksize: 500}, `{"algorithm":"highwayhash","blocksize":500,"hashes":null}`},
|
||||
{FSChecksumInfoV1{Algorithm: "highwayhash", Blocksize: 10, Hashes: [][]byte{[]byte("hello")}}, `{"algorithm":"highwayhash","blocksize":10,"hashes":["68656c6c6f"]}`},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
data, _ := testCase.checksum.MarshalJSON()
|
||||
if testCase.expectedResult != string(data) {
|
||||
t.Fatalf("expected: %v, got: %v", testCase.expectedResult, string(data))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFSChecksumV1UnMarshalJSON(t *testing.T) {
|
||||
var cs FSChecksumInfoV1
|
||||
|
||||
testCases := []struct {
|
||||
data []byte
|
||||
expectedResult FSChecksumInfoV1
|
||||
}{
|
||||
{[]byte(`{"algorithm":"","blocksize":0,"hashes":null}`), cs},
|
||||
{[]byte(`{"algorithm":"highwayhash","blocksize":500,"hashes":null}`), FSChecksumInfoV1{Algorithm: "highwayhash", Blocksize: 500}},
|
||||
{[]byte(`{"algorithm":"highwayhash","blocksize":10,"hashes":["68656c6c6f"]}`), FSChecksumInfoV1{Algorithm: "highwayhash", Blocksize: 10, Hashes: [][]byte{[]byte("hello")}}},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
err := (&cs).UnmarshalJSON(testCase.data)
|
||||
if err != nil {
|
||||
t.Fatal("Unexpected error during checksum unmarshalling ", err)
|
||||
}
|
||||
if !reflect.DeepEqual(testCase.expectedResult, cs) {
|
||||
t.Fatalf("expected: %v, got: %v", testCase.expectedResult, cs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user