Commit d0140610 authored by Zhu Yong's avatar Zhu Yong
Browse files

add test case for buffer overflow, drive send status using UNSOLICITEDSTATUS,...

add test case for buffer overflow, drive send status using UNSOLICITEDSTATUS, without AckSeq, need review
parent 058dca53
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
package kinetic

import (
	"bytes"
	"os"
	"testing"
)
@@ -89,6 +90,57 @@ func TestBlockPut(t *testing.T) {
	}
}

// TestBlockPut_keyOverflow test key buffer length than MaxKeySize
// TODO: drive implementation using UNSOLICITEDSTATUS for Key too long.
func TestBlockPut_keyOverflow(t *testing.T) {
	entry := Record{
		Key:   bytes.Repeat([]byte("K"), int(blockConn.nbc.service.device.Limits.MaxKeySize+1)),
		Value: []byte("ABCDEFG"),
		Sync:  SYNC_WRITETHROUGH,
		Algo:  ALGO_SHA1,
		Tag:   []byte(""),
		Force: true,
	}
	status, err := blockConn.Put(&entry)
	if err != nil || status.Code != OK {
		t.Fatal("Blocking Put Failure", err, status.String())
	}
}

// TestBlockPut_valueOverflow test key buffer length than MaxValueSize
// TODO: drive implementation using UNSOLICITEDSTATUS.
func TestBlockPut_valueOverflow(t *testing.T) {
	entry := Record{
		Key:   []byte("key"),
		Value: bytes.Repeat([]byte("V"), int(blockConn.nbc.service.device.Limits.MaxValueSize+1)),
		Sync:  SYNC_WRITETHROUGH,
		Algo:  ALGO_SHA1,
		Tag:   []byte(""),
		Force: true,
	}
	status, err := blockConn.Put(&entry)
	if err != nil || status.Code != OK {
		t.Fatal("Blocking Put Failure", err, status.String())
	}
}

// TestBlockPut_tagOverflow test key buffer length than MaxTagSize
// TODO: drive implementation using UNSOLICITEDSTATUS.
func TestBlockPut_tagOverflow(t *testing.T) {
	entry := Record{
		Key:   []byte("key"),
		Value: []byte("value"),
		Sync:  SYNC_WRITETHROUGH,
		Algo:  ALGO_SHA1,
		Tag:   bytes.Repeat([]byte("T"), int(blockConn.nbc.service.device.Limits.MaxTagSize+1)),
		Force: true,
	}
	status, err := blockConn.Put(&entry)
	if err != nil || status.Code != OK {
		t.Fatal("Blocking Put Failure", err, status.String())
	}
}

func TestBlockDelete(t *testing.T) {
	entry := Record{
		Key:   []byte("object000"),