mirror of
https://github.com/minio/minio.git
synced 2024-12-27 23:55:56 -05:00
Add donut tests, just for verification
This commit is contained in:
parent
aa2c622f52
commit
c4f0aad9b5
@ -17,12 +17,14 @@
|
|||||||
package donut
|
package donut
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** DONUT v1 Spec **
|
|
||||||
|
|
||||||
|
DONUT v1 Spec
|
||||||
|
**********************
|
||||||
BlockStart [4]byte // Magic="MINI"
|
BlockStart [4]byte // Magic="MINI"
|
||||||
VersionMajor uint16
|
VersionMajor uint16
|
||||||
VersionMinor uint16
|
VersionMinor uint16
|
||||||
@ -35,6 +37,7 @@ import (
|
|||||||
Data io.Reader // matches length
|
Data io.Reader // matches length
|
||||||
BlockLen uint64 // length to block start
|
BlockLen uint64 // length to block start
|
||||||
BlockEnd [4]byte // Magic="INIM"
|
BlockEnd [4]byte // Magic="INIM"
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type DonutStructure struct {
|
type DonutStructure struct {
|
||||||
@ -81,10 +84,25 @@ func (donut *Donut) Write(gobHeader GobHeader, object io.Reader) error {
|
|||||||
BlockLen: 0,
|
BlockLen: 0,
|
||||||
BlockEnd: [4]byte{'I', 'N', 'I', 'M'},
|
BlockEnd: [4]byte{'I', 'N', 'I', 'M'},
|
||||||
}
|
}
|
||||||
if err := WriteStructure(donut.file, donutStructure); err != nil {
|
if err := donut.WriteStructure(donut.file, donutStructure); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteStructure(target io.Writer, donutStructure DonutStructure) error { return nil }
|
func (donut *Donut) WriteStructure(target io.Writer, donutStructure DonutStructure) error {
|
||||||
|
err := binary.Write(target, binary.LittleEndian, donutStructure.BlockStart)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.VersionMajor)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.VersionMinor)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.VersionPatch)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.VersionReserved)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.Reserved)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.GobHeaderLen)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.GobHeader)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.BlockData)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.Data)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.BlockLen)
|
||||||
|
err = binary.Write(target, binary.LittleEndian, donutStructure.BlockEnd)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
52
pkg/storage/donut/donut_test.go
Normal file
52
pkg/storage/donut/donut_test.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Mini Object Storage, (C) 2015 Minio, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package donut
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test(t *testing.T) { TestingT(t) }
|
||||||
|
|
||||||
|
type MySuite struct{}
|
||||||
|
|
||||||
|
var _ = Suite(&MySuite{})
|
||||||
|
|
||||||
|
func (s *MySuite) TestAPISuite(c *C) {
|
||||||
|
var b bytes.Buffer
|
||||||
|
var o bytes.Buffer
|
||||||
|
|
||||||
|
donut := Donut{&b}
|
||||||
|
gobheader := GobHeader{}
|
||||||
|
err := donut.Write(gobheader, &o)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Log(b.Bytes())
|
||||||
|
blockStart := make([]byte, 4)
|
||||||
|
blockEnd := make([]byte, 4)
|
||||||
|
|
||||||
|
n, _ := b.Read(blockStart)
|
||||||
|
b.Next(b.Len() - n) // jump ahead
|
||||||
|
b.Read(blockEnd)
|
||||||
|
|
||||||
|
blockStartCheck := []byte{'M', 'I', 'N', 'I'}
|
||||||
|
blockEndCheck := []byte{'I', 'N', 'I', 'M'}
|
||||||
|
|
||||||
|
c.Assert(blockStart, DeepEquals, blockStartCheck)
|
||||||
|
c.Assert(blockEnd, DeepEquals, blockEndCheck)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user