func TestEncodeDBOperationToJson_CreateNodeOp(t *testing.T) {
	json, err := i.EncodeDBOperationsToJson([]i.DBOperation{&i.CreateNodeOp{
		NodeLock: i.NodeLock{ID: 123, Ticket: 456},
		OrigPath: "/foo/bar",
		Type:     i.DirNodeT,
	}})
	if err != nil {
		t.Errorf("EncodeDBOperationToJson failed: %v", err)
		return
	}

	ops, err := i.DecodeDBOperationsFromJson(json)
	if err != nil {
		t.Errorf("DecodeDBOperationToJson failed: %v", err)
		return
	}

	dirop, ok := ops[0].(*i.CreateNodeOp)
	if !ok {
		t.Errorf("Decode failed to recover original type")
	}

	if dirop.NodeLock.ID != 123 {
		t.Errorf("encode/decode data mismatch")
	}
	if dirop.NodeLock.Ticket != 456 {
		t.Errorf("encode/decode data mismatch")
	}
	if dirop.OrigPath != "/foo/bar" {
		t.Errorf("encode/decode data mismatch")
	}
}
Example #2
0
func encode(c btncrypt.Cipher, tx inodedb.DBTransaction) (*storedbtx, error) {
	jsonops, err := inodedb.EncodeDBOperationsToJson(tx.Ops)
	if err != nil {
		return nil, fmt.Errorf("Failed to encode dbtx: %v", err)
	}

	env, err := btncrypt.Encrypt(c, jsonops)
	if err != nil {
		return nil, fmt.Errorf("Failed to decrypt OpsJSON: %v", err)
	}

	return &storedbtx{TxID: int64(tx.TxID), OpsJSON: env}, nil
}
Example #3
0
func (txio *DBTransactionLogIO) encode(tx inodedb.DBTransaction) (*datastore.Key, *storedbtx, error) {
	key := txio.encodeKey(tx.TxID)

	jsonops, err := inodedb.EncodeDBOperationsToJson(tx.Ops)
	if err != nil {
		return nil, nil, fmt.Errorf("Failed to encode dbtx: %v", err)
	}

	c := txio.cfg.c
	env, err := btncrypt.Encrypt(c, jsonops)
	if err != nil {
		return nil, nil, fmt.Errorf("Failed to encrypt OpsJSON: %v", err)
	}

	return key, &storedbtx{OpsJSON: env}, nil
}
func TestEncodeDBOperationToJson_InitializeFileSystemOp(t *testing.T) {
	json, err := i.EncodeDBOperationsToJson([]i.DBOperation{&i.InitializeFileSystemOp{}})
	if err != nil {
		t.Errorf("EncodeDBOperationToJson failed: %v", err)
		return
	}

	// t.Errorf("%v", string(json))
	ops, err := i.DecodeDBOperationsFromJson(json)
	if err != nil {
		t.Errorf("DecodeDBOperationToJson failed: %v", err)
		return
	}
	if _, ok := ops[0].(*i.InitializeFileSystemOp); !ok {
		t.Errorf("Decode failed to recover original type")
	}
}