Further fixes -

- All test files have been renamed to their respective <package>_test name,
    this is done in accordance with
      - https://github.com/golang/go/wiki/CodeReviewComments#import-dot
        imports are largely used in testing, but to avoid namespace collision
        and circular dependencies

  - Never use _* in package names other than "_test" change fragment_v1 to expose
    fragment just like 'gopkg.in/check.v1'
This commit is contained in:
Harshavardhana
2015-03-06 01:50:51 -08:00
parent 02ccf123c9
commit e5af8a3f5d
24 changed files with 245 additions and 285 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package erasure_v1
package erasure
import (
"bytes"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package erasure_v1
package erasure
import (
"bytes"

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package fragment_v1
package fragment
import (
"bytes"

View File

@@ -1,2 +0,0 @@
donut_gen
hello

View File

@@ -1,59 +0,0 @@
package main
import (
"bytes"
"fmt"
"os"
"reflect"
"github.com/minio-io/minio/pkg/storage/donut/fragment/fragment_v1"
)
func main() {
fmt.Println("--start")
file, err := os.OpenFile("newfile", os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
panic(err)
}
data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
dataBuffer := bytes.NewBuffer(data)
err = fragment_v1.WriteFrame(file, dataBuffer, uint64(dataBuffer.Len()))
if err != nil {
panic(err)
}
file.Close()
fmt.Println("--closed")
fmt.Println("--verify")
stat, _ := os.Stat("newfile")
fileSize := stat.Size()
rfile, _ := os.OpenFile("newfile", os.O_RDONLY, 0666)
blockStart := make([]byte, 4)
blockStartCheck := []byte{'M', 'I', 'N', 'I'}
_, err = rfile.Read(blockStart)
if err != nil {
panic(err)
}
blockEnd := make([]byte, 4)
start := fileSize - 4
blockEndCheck := []byte{'I', 'N', 'I', 'M'}
rfile.ReadAt(blockEnd, start)
rfile.Close()
if !reflect.DeepEqual(blockStart, blockStartCheck) {
panic("Corrupted donut file")
}
if !reflect.DeepEqual(blockEnd, blockEndCheck) {
panic("Corrupted donut file")
}
fmt.Println("--verified")
fmt.Println("--end")
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package fragment_v1
package fragment_test
import (
"bytes"
@@ -22,8 +22,8 @@ import (
"encoding/binary"
"testing"
"github.com/minio-io/minio/pkg/storage/donut/fragment/fragment_v1"
"github.com/minio-io/minio/pkg/utils/checksum/crc32c"
. "gopkg.in/check.v1"
)
@@ -39,7 +39,7 @@ func (s *MySuite) TestSingleWrite(c *C) {
testData := "Hello, World"
testLength := uint64(len(testData))
err := WriteFrame(&testBuffer, bytes.NewBufferString(testData), testLength)
err := fragment.WriteFrame(&testBuffer, bytes.NewBufferString(testData), testLength)
c.Assert(err, IsNil)
testBufferLength := uint64(testBuffer.Len())
@@ -112,7 +112,7 @@ func (s *MySuite) TestSingleWrite(c *C) {
func (s *MySuite) TestLengthMismatchInWrite(c *C) {
var testData bytes.Buffer
err := WriteFrame(&testData, bytes.NewBufferString("hello, world"), 5)
err := fragment.WriteFrame(&testData, bytes.NewBufferString("hello, world"), 5)
c.Assert(err, Not(IsNil))
}
@@ -122,7 +122,7 @@ func benchmarkSize(b *testing.B, size int) {
b.SetBytes(int64(size))
target := new(bytes.Buffer)
for i := 0; i < b.N; i++ {
WriteFrame(target, bytes.NewReader(buf[:size]), uint64(size))
fragment.WriteFrame(target, bytes.NewReader(buf[:size]), uint64(size))
}
}