mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 14:15:06 +03:00
db entity fix
db entity fix added sql. NullTime struct
This commit is contained in:
parent
80ea41600f
commit
e9e79ac3f4
11 changed files with 295 additions and 126 deletions
244
src/core/db.go
244
src/core/db.go
|
@ -12,52 +12,71 @@ import (
|
||||||
|
|
||||||
type PeerInfoDB struct {
|
type PeerInfoDB struct {
|
||||||
PeerInfo
|
PeerInfo
|
||||||
Id int
|
Id int
|
||||||
CoordsBytes []byte
|
Coords Blob
|
||||||
KeyBytes []byte
|
Key PublicKeyContainer
|
||||||
RootBytes []byte
|
Root PublicKeyContainer
|
||||||
PeerErr sql.NullString
|
Error ErrorContainer
|
||||||
|
LastErrorTime sql.NullTime
|
||||||
}
|
}
|
||||||
|
|
||||||
type SelfInfoDB struct {
|
type SelfInfoDB struct {
|
||||||
SelfInfo
|
SelfInfo
|
||||||
Id int
|
Id int
|
||||||
KeyBytes []byte
|
Key PublicKeyContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
type TreeEntryInfoDB struct {
|
type TreeEntryInfoDB struct {
|
||||||
TreeEntryInfo
|
TreeEntryInfo
|
||||||
Id int
|
Id int
|
||||||
KeyBytes []byte
|
Key PublicKeyContainer
|
||||||
ParentBytes []byte
|
Parent PublicKeyContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
type PathEntryInfoDB struct {
|
type PathEntryInfoDB struct {
|
||||||
PathEntryInfo
|
PathEntryInfo
|
||||||
Id int
|
Id int
|
||||||
KeyBytes []byte
|
Key PublicKeyContainer
|
||||||
PathBytes []byte
|
Path Blob
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionInfoDB struct {
|
type SessionInfoDB struct {
|
||||||
SessionInfo
|
SessionInfo
|
||||||
Id int
|
Id int
|
||||||
KeyBytes []byte
|
Key PublicKeyContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPeerInfoDB(peerInfo PeerInfo) (_ *PeerInfoDB, err error) {
|
func NewPeerInfoDB(peerInfo PeerInfo) (_ *PeerInfoDB, err error) {
|
||||||
peer := &PeerInfoDB{
|
peer := &PeerInfoDB{
|
||||||
PeerInfo: peerInfo,
|
PeerInfo: peerInfo,
|
||||||
}
|
}
|
||||||
peer.PeerErr = MarshalError(peer.LastError)
|
peer.Error = ErrorContainer{
|
||||||
peer.CoordsBytes = ConvertToByteSlise(peer.Coords)
|
_err: peerInfo.LastError,
|
||||||
peer.KeyBytes, err = MarshalPKIXPublicKey(&peer.Key)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
peer.RootBytes, err = MarshalPKIXPublicKey(&peer.Root)
|
peer.Error.ParseError(peerInfo.LastError)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
peer.Coords = Blob{
|
||||||
|
_uint: peerInfo.Coords,
|
||||||
|
}
|
||||||
|
peer.Coords.ParseUint64Sliсe(peer.Coords._uint)
|
||||||
|
|
||||||
|
peer.Key = PublicKeyContainer{
|
||||||
|
_publicKey: peerInfo.Key,
|
||||||
|
}
|
||||||
|
publicKey := peer.Key.GetPKIXPublicKey()
|
||||||
|
peer.Key.MarshalPKIXPublicKey(&publicKey)
|
||||||
|
|
||||||
|
peer.Root = PublicKeyContainer{
|
||||||
|
_publicKey: peerInfo.Root,
|
||||||
|
}
|
||||||
|
publicKey = peer.Root.GetPKIXPublicKey()
|
||||||
|
peer.Root.MarshalPKIXPublicKey(&publicKey)
|
||||||
|
peer.LastErrorTime = sql.NullTime{}
|
||||||
|
if !peerInfo.LastErrorTime.IsZero() {
|
||||||
|
peer.LastErrorTime.Time = peerInfo.LastErrorTime
|
||||||
|
peer.LastErrorTime.Valid = true
|
||||||
|
} else {
|
||||||
|
peer.LastErrorTime.Valid = false
|
||||||
}
|
}
|
||||||
return peer, nil
|
return peer, nil
|
||||||
}
|
}
|
||||||
|
@ -66,7 +85,11 @@ func NewSelfInfoDB(selfinfo SelfInfo) (_ *SelfInfoDB, err error) {
|
||||||
model := &SelfInfoDB{
|
model := &SelfInfoDB{
|
||||||
SelfInfo: selfinfo,
|
SelfInfo: selfinfo,
|
||||||
}
|
}
|
||||||
model.KeyBytes, err = MarshalPKIXPublicKey(&model.Key)
|
model.Key = PublicKeyContainer{
|
||||||
|
_publicKey: selfinfo.Key,
|
||||||
|
}
|
||||||
|
publicKey := model.Key.GetPKIXPublicKey()
|
||||||
|
model.Key.MarshalPKIXPublicKey(&publicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -77,14 +100,16 @@ func NewTreeEntryInfoDB(treeEntyInfo TreeEntryInfo) (_ *TreeEntryInfoDB, err err
|
||||||
model := &TreeEntryInfoDB{
|
model := &TreeEntryInfoDB{
|
||||||
TreeEntryInfo: treeEntyInfo,
|
TreeEntryInfo: treeEntyInfo,
|
||||||
}
|
}
|
||||||
model.KeyBytes, err = MarshalPKIXPublicKey(&model.Key)
|
model.Key = PublicKeyContainer{
|
||||||
if err != nil {
|
_publicKey: treeEntyInfo.Key,
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
model.ParentBytes, err = MarshalPKIXPublicKey(&model.Parent)
|
publicKey := model.Key.GetPKIXPublicKey()
|
||||||
if err != nil {
|
model.Key.MarshalPKIXPublicKey(&publicKey)
|
||||||
return nil, err
|
model.Parent = PublicKeyContainer{
|
||||||
|
_publicKey: treeEntyInfo.Parent,
|
||||||
}
|
}
|
||||||
|
publicKey = model.Parent.GetPKIXPublicKey()
|
||||||
|
model.Parent.MarshalPKIXPublicKey(&publicKey)
|
||||||
return model, nil
|
return model, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,12 +117,16 @@ func NewPathEntryInfoDB(PathEntryInfo PathEntryInfo) (_ *PathEntryInfoDB, err er
|
||||||
model := &PathEntryInfoDB{
|
model := &PathEntryInfoDB{
|
||||||
PathEntryInfo: PathEntryInfo,
|
PathEntryInfo: PathEntryInfo,
|
||||||
}
|
}
|
||||||
model.KeyBytes, err = MarshalPKIXPublicKey(&model.Key)
|
model.Key = PublicKeyContainer{
|
||||||
if err != nil {
|
_publicKey: PathEntryInfo.Key,
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
model.PathBytes = ConvertToByteSlise(model.Path)
|
publicKey := model.Key.GetPKIXPublicKey()
|
||||||
|
model.Key.MarshalPKIXPublicKey(&publicKey)
|
||||||
|
|
||||||
|
model.Path = Blob{
|
||||||
|
_uint: PathEntryInfo.Path,
|
||||||
|
}
|
||||||
|
model.Path.ParseUint64Sliсe(model.Path._uint)
|
||||||
return model, nil
|
return model, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,25 +134,146 @@ func NewSessionInfoDB(SessionInfo SessionInfo) (_ *SessionInfoDB, err error) {
|
||||||
model := &SessionInfoDB{
|
model := &SessionInfoDB{
|
||||||
SessionInfo: SessionInfo,
|
SessionInfo: SessionInfo,
|
||||||
}
|
}
|
||||||
model.KeyBytes, err = MarshalPKIXPublicKey(&model.Key)
|
model.Key = PublicKeyContainer{
|
||||||
if err != nil {
|
_publicKey: SessionInfo.Key,
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
publicKey := model.Key.GetPKIXPublicKey()
|
||||||
|
model.Key.MarshalPKIXPublicKey(&publicKey)
|
||||||
return model, nil
|
return model, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertToByteSlise(uintSlise []uint64) []byte {
|
type Blob struct {
|
||||||
var ByteSlise []byte
|
_byte []byte
|
||||||
if uintSlise != nil {
|
_uint []uint64
|
||||||
ByteSlise = make([]byte, len(uintSlise)*8)
|
|
||||||
for i, coord := range uintSlise {
|
|
||||||
binary.LittleEndian.PutUint64(ByteSlise[i*8:], coord)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ByteSlise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertToUintSlise(ByteSlise []byte) (_ []uint64, err error) {
|
type PublicKeyContainer struct {
|
||||||
|
_byte []byte
|
||||||
|
_publicKey ed25519.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
type ErrorContainer struct {
|
||||||
|
_ErrStr sql.NullString
|
||||||
|
_err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (blob *PublicKeyContainer) GetPKIXPublicKeyBytes() []byte {
|
||||||
|
if blob._publicKey == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
result, err := MarshalPKIXPublicKey(&blob._publicKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (blob *PublicKeyContainer) GetPKIXPublicKey() ed25519.PublicKey {
|
||||||
|
if blob._publicKey == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return blob._publicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
func (blob *PublicKeyContainer) ParsePKIXPublicKey(derBytes *[]byte) {
|
||||||
|
result, err := ParsePKIXPublicKey(derBytes)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
blob._byte = *derBytes
|
||||||
|
blob._publicKey = result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (blob *PublicKeyContainer) MarshalPKIXPublicKey(PublicKey *ed25519.PublicKey) {
|
||||||
|
result, err := MarshalPKIXPublicKey(PublicKey)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
blob._publicKey = *PublicKey
|
||||||
|
blob._byte = result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (blob *Blob) ConvertToUintSliсe() []uint64 {
|
||||||
|
if blob._byte == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
result, err := ConvertToUintSliсe(blob._byte)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (blob *Blob) ConvertToByteSliсe() []byte {
|
||||||
|
if blob._uint == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
result := ConvertToByteSliсe(blob._uint)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (blob *Blob) ParseByteSliсe(slice []byte) {
|
||||||
|
result, err := ConvertToUintSliсe(slice)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
blob._byte = slice
|
||||||
|
blob._uint = result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (blob *Blob) ParseUint64Sliсe(slice []uint64) {
|
||||||
|
blob._uint = slice
|
||||||
|
blob._byte = ConvertToByteSliсe(slice)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ErrorContainer *ErrorContainer) ParseError(err error) {
|
||||||
|
if err != nil {
|
||||||
|
ErrorContainer._ErrStr = sql.NullString{
|
||||||
|
String: err.Error(),
|
||||||
|
Valid: true}
|
||||||
|
ErrorContainer._err = err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ErrorContainer *ErrorContainer) ParseMessage(message string) {
|
||||||
|
if message != "" {
|
||||||
|
ErrorContainer._ErrStr = sql.NullString{
|
||||||
|
String: message,
|
||||||
|
Valid: true}
|
||||||
|
ErrorContainer._err = errors.New(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ErrorContainer *ErrorContainer) GetError() error {
|
||||||
|
if ErrorContainer._err != nil {
|
||||||
|
return ErrorContainer._err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ErrorContainer *ErrorContainer) GetErrorMessage() string {
|
||||||
|
if ErrorContainer._ErrStr.Valid {
|
||||||
|
return ErrorContainer._ErrStr.String
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ErrorContainer *ErrorContainer) GetErrorSqlError() sql.NullString {
|
||||||
|
return ErrorContainer._ErrStr
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertToByteSliсe(uintSlice []uint64) []byte {
|
||||||
|
var ByteSlice []byte
|
||||||
|
if uintSlice != nil {
|
||||||
|
ByteSlice = make([]byte, len(uintSlice)*8)
|
||||||
|
for i, coord := range uintSlice {
|
||||||
|
binary.LittleEndian.PutUint64(ByteSlice[i*8:], coord)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ByteSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertToUintSliсe(ByteSlise []byte) (_ []uint64, err error) {
|
||||||
if len(ByteSlise)%8 != 0 {
|
if len(ByteSlise)%8 != 0 {
|
||||||
return nil, fmt.Errorf("length of byte slice must be a multiple of 8")
|
return nil, fmt.Errorf("length of byte slice must be a multiple of 8")
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,8 @@ func (cfg *PathEntryInfoDBConfig) Add(model *core.PathEntryInfoDB) (_ sql.Result
|
||||||
query := "INSERT INTO path_entry_info (Key, Path, Sequence) VALUES (?, ?, ?)"
|
query := "INSERT INTO path_entry_info (Key, Path, Sequence) VALUES (?, ?, ?)"
|
||||||
result, err := cfg.DbConfig.DB.Exec(
|
result, err := cfg.DbConfig.DB.Exec(
|
||||||
query,
|
query,
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.PathBytes,
|
model.Path.ConvertToByteSliсe(),
|
||||||
model.Sequence)
|
model.Sequence)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -74,7 +74,7 @@ func (cfg *PathEntryInfoDBConfig) Update(model *core.PathEntryInfoDB) (err error
|
||||||
Path = ?
|
Path = ?
|
||||||
WHERE
|
WHERE
|
||||||
Id = ?`,
|
Id = ?`,
|
||||||
model.Sequence, model.KeyBytes, model.PathBytes, model.Id)
|
model.Sequence, model.Key.GetPKIXPublicKeyBytes(), model.Path.ConvertToByteSliсe(), model.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,15 @@ func (cfg *PathEntryInfoDBConfig) Get(model *core.PathEntryInfoDB) (_ *sql.Rows,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
var _key []byte
|
||||||
|
var _path []byte
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err = rows.Scan(&model.Sequence, &model.KeyBytes, &model.PathBytes)
|
err = rows.Scan(&model.Sequence, &_key, &_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
model.Key.ParsePKIXPublicKey(&_key)
|
||||||
|
model.Path.ParseByteSliсe(_path)
|
||||||
}
|
}
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,11 +57,11 @@ func (cfg *PeerInfoDBConfig) Add(model *core.PeerInfoDB) (_ sql.Result, err erro
|
||||||
model.URI,
|
model.URI,
|
||||||
model.Up,
|
model.Up,
|
||||||
model.Inbound,
|
model.Inbound,
|
||||||
model.PeerErr,
|
model.Error.GetErrorMessage(),
|
||||||
model.LastErrorTime,
|
model.LastErrorTime,
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.RootBytes,
|
model.Root.GetPKIXPublicKeyBytes(),
|
||||||
model.CoordsBytes,
|
model.Coords.ConvertToByteSliсe(),
|
||||||
model.Port,
|
model.Port,
|
||||||
model.Priority,
|
model.Priority,
|
||||||
model.RXBytes,
|
model.RXBytes,
|
||||||
|
@ -101,30 +101,22 @@ func (cfg *PeerInfoDBConfig) Get(model *core.PeerInfoDB) (_ *sql.Rows, err error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
var _key []byte
|
||||||
|
var _root []byte
|
||||||
|
var _err string
|
||||||
|
var _coords []byte
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err = rows.Scan(&model.Up, &model.Inbound, &model.PeerErr, &model.LastErrorTime, &model.CoordsBytes,
|
err = rows.Scan(&model.Up, &model.Inbound, &_err, &model.LastErrorTime, &_coords,
|
||||||
&model.Port, &model.Priority, &model.RXBytes, &model.TXBytes, &model.Uptime, &model.Latency,
|
&model.Port, &model.Priority, &model.RXBytes, &model.TXBytes, &model.Uptime, &model.Latency,
|
||||||
&model.URI, &model.KeyBytes, &model.RootBytes)
|
&model.URI, &_key, &_root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rows, err
|
return rows, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
model.Coords.ParseByteSliсe(_coords)
|
||||||
model.Coords, err = core.ConvertToUintSlise(model.CoordsBytes)
|
model.Key.ParsePKIXPublicKey(&_key)
|
||||||
if err != nil {
|
model.Root.ParsePKIXPublicKey(&_root)
|
||||||
return nil, err
|
model.Error.ParseMessage(_err)
|
||||||
}
|
|
||||||
publickey, err := core.ParsePKIXPublicKey(&model.KeyBytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
model.Key = publickey
|
|
||||||
publicRoot, err := core.ParsePKIXPublicKey(&model.RootBytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
model.Root = publicRoot
|
|
||||||
model.LastError = core.ParseError(model.PeerErr)
|
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,8 +139,8 @@ func (cfg *PeerInfoDBConfig) Update(model *core.PeerInfoDB) (err error) {
|
||||||
root = ?
|
root = ?
|
||||||
WHERE
|
WHERE
|
||||||
Id = ?`,
|
Id = ?`,
|
||||||
model.Up, model.Inbound, model.PeerErr, model.LastErrorTime, model.CoordsBytes, model.Port, model.Priority,
|
model.Up, model.Inbound, model.Error.GetErrorSqlError(), model.LastErrorTime, model.Coords.ConvertToByteSliсe(), model.Port, model.Priority,
|
||||||
model.RXBytes, model.TXBytes, model.Uptime, model.Latency, model.URI, model.KeyBytes, model.RootBytes, model.Id)
|
model.RXBytes, model.TXBytes, model.Uptime, model.Latency, model.URI, model.Key.GetPKIXPublicKeyBytes(), model.Root.GetPKIXPublicKeyBytes(), model.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func New() (*SelfInfoDBConfig, error) {
|
||||||
func (cfg *SelfInfoDBConfig) Add(model *core.SelfInfoDB) (_ sql.Result, err error) {
|
func (cfg *SelfInfoDBConfig) Add(model *core.SelfInfoDB) (_ sql.Result, err error) {
|
||||||
query := "INSERT OR REPLACE INTO self_info (Key, RoutingEntries) VALUES (?, ?)"
|
query := "INSERT OR REPLACE INTO self_info (Key, RoutingEntries) VALUES (?, ?)"
|
||||||
result, err := cfg.DbConfig.DB.Exec(query,
|
result, err := cfg.DbConfig.DB.Exec(query,
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.RoutingEntries)
|
model.RoutingEntries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -61,7 +61,7 @@ func (cfg *SelfInfoDBConfig) Update(model *core.SelfInfoDB) (err error) {
|
||||||
Key = ?
|
Key = ?
|
||||||
WHERE
|
WHERE
|
||||||
Id = ?`,
|
Id = ?`,
|
||||||
model.RoutingEntries, model.KeyBytes, model.Id)
|
model.RoutingEntries, model.Key.GetPKIXPublicKeyBytes(), model.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -84,11 +84,13 @@ func (cfg *SelfInfoDBConfig) Get(model *core.SelfInfoDB) (_ *sql.Rows, err error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
var _key []byte
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err = rows.Scan(&model.RoutingEntries, &model.KeyBytes)
|
err = rows.Scan(&model.RoutingEntries, &_key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rows, err
|
return rows, err
|
||||||
}
|
}
|
||||||
|
model.Key.ParsePKIXPublicKey(&_key)
|
||||||
}
|
}
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func New() (*SessionInfoDBConfig, error) {
|
||||||
func (cfg *SessionInfoDBConfig) Add(model *core.SessionInfoDB) (_ sql.Result, err error) {
|
func (cfg *SessionInfoDBConfig) Add(model *core.SessionInfoDB) (_ sql.Result, err error) {
|
||||||
query := "INSERT INTO session_info (Key, RXBytes, TXBytes, Duration) VALUES (?, ?, ?, ?)"
|
query := "INSERT INTO session_info (Key, RXBytes, TXBytes, Duration) VALUES (?, ?, ?, ?)"
|
||||||
result, err := cfg.DbConfig.DB.Exec(query,
|
result, err := cfg.DbConfig.DB.Exec(query,
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.RXBytes,
|
model.RXBytes,
|
||||||
model.TXBytes,
|
model.TXBytes,
|
||||||
model.Uptime,
|
model.Uptime,
|
||||||
|
@ -77,7 +77,7 @@ func (cfg *SessionInfoDBConfig) Update(model *core.SessionInfoDB) (err error) {
|
||||||
Key = ?
|
Key = ?
|
||||||
WHERE
|
WHERE
|
||||||
Id = ?`,
|
Id = ?`,
|
||||||
model.RXBytes, model.TXBytes, model.Uptime, model.KeyBytes, model.Id)
|
model.RXBytes, model.TXBytes, model.Uptime, model.Key.GetPKIXPublicKeyBytes(), model.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -92,11 +92,13 @@ func (cfg *SessionInfoDBConfig) Get(model *core.SessionInfoDB) (_ *sql.Rows, err
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
var _key []byte
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err = rows.Scan(&model.RXBytes, &model.TXBytes, &model.Uptime, &model.KeyBytes)
|
err = rows.Scan(&model.RXBytes, &model.TXBytes, &model.Uptime, &_key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
model.Key.ParsePKIXPublicKey(&_key)
|
||||||
}
|
}
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,8 @@ func New() (*TreeEntryInfoDBConfig, error) {
|
||||||
func (cfg *TreeEntryInfoDBConfig) Add(model *core.TreeEntryInfoDB) (_ sql.Result, err error) {
|
func (cfg *TreeEntryInfoDBConfig) Add(model *core.TreeEntryInfoDB) (_ sql.Result, err error) {
|
||||||
query := "INSERT INTO tree_entry_info (Key, Parent, Sequence) VALUES (?, ?, ?)"
|
query := "INSERT INTO tree_entry_info (Key, Parent, Sequence) VALUES (?, ?, ?)"
|
||||||
result, err := cfg.DbConfig.DB.Exec(query,
|
result, err := cfg.DbConfig.DB.Exec(query,
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.ParentBytes,
|
model.Parent.GetPKIXPublicKeyBytes(),
|
||||||
model.Sequence,
|
model.Sequence,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,7 +74,7 @@ func (cfg *TreeEntryInfoDBConfig) Update(model *core.TreeEntryInfoDB) (err error
|
||||||
Parent = ?
|
Parent = ?
|
||||||
WHERE
|
WHERE
|
||||||
Id = ?`,
|
Id = ?`,
|
||||||
model.Sequence, model.KeyBytes, model.ParentBytes, model.Id)
|
model.Sequence, model.Key.GetPKIXPublicKeyBytes(), model.Parent.GetPKIXPublicKeyBytes(), model.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,15 @@ func (cfg *TreeEntryInfoDBConfig) Get(model *core.TreeEntryInfoDB) (_ *sql.Rows,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
var _key []byte
|
||||||
|
var _path []byte
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err = rows.Scan(&model.Sequence, &model.KeyBytes, &model.ParentBytes)
|
err = rows.Scan(&model.Sequence, &_key, &_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
model.Key.ParsePKIXPublicKey(&_key)
|
||||||
|
model.Parent.ParsePKIXPublicKey(&_path)
|
||||||
}
|
}
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package db_test
|
||||||
import (
|
import (
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -21,12 +22,11 @@ func TestPeerGetCoords(t *testing.T) {
|
||||||
peerinfo := core.PeerInfo{
|
peerinfo := core.PeerInfo{
|
||||||
Coords: []uint64{1, 2, 3, 4},
|
Coords: []uint64{1, 2, 3, 4},
|
||||||
}
|
}
|
||||||
peer := core.PeerInfoDB{
|
peer, err := core.NewPeerInfoDB(peerinfo)
|
||||||
PeerInfo: peerinfo,
|
require.NoError(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
target := []byte{1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0}
|
target := []byte{1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0}
|
||||||
coordinates := core.ConvertToByteSlise(peer.Coords)
|
coordinates := peer.Coords.ConvertToByteSliсe()
|
||||||
if !reflect.DeepEqual(target, coordinates) {
|
if !reflect.DeepEqual(target, coordinates) {
|
||||||
t.Error(fmt.Errorf("Not equal"))
|
t.Error(fmt.Errorf("Not equal"))
|
||||||
}
|
}
|
||||||
|
@ -34,15 +34,12 @@ func TestPeerGetCoords(t *testing.T) {
|
||||||
|
|
||||||
func TestPeerSetCoords(t *testing.T) {
|
func TestPeerSetCoords(t *testing.T) {
|
||||||
peerinfo := core.PeerInfo{}
|
peerinfo := core.PeerInfo{}
|
||||||
peer := core.PeerInfoDB{
|
peer, err := core.NewPeerInfoDB(peerinfo)
|
||||||
PeerInfo: peerinfo,
|
require.NoError(t, err)
|
||||||
}
|
peer.Coords.ParseByteSliсe([]byte{4, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0})
|
||||||
var err error
|
|
||||||
peer.CoordsBytes = []byte{4, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}
|
|
||||||
peer.Coords, err = core.ConvertToUintSlise(peer.CoordsBytes)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
coords := []uint64{4, 3, 2, 1}
|
coords := []uint64{4, 3, 2, 1}
|
||||||
if !reflect.DeepEqual(coords, peer.Coords) {
|
if !reflect.DeepEqual(coords, peer.Coords.ConvertToUintSliсe()) {
|
||||||
t.Error(fmt.Errorf("Not equal"))
|
t.Error(fmt.Errorf("Not equal"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,11 +80,11 @@ func TestAddPeer(t *testing.T) {
|
||||||
peer.URI,
|
peer.URI,
|
||||||
peer.Up,
|
peer.Up,
|
||||||
peer.Inbound,
|
peer.Inbound,
|
||||||
peer.PeerErr,
|
peer.Error.GetErrorMessage(),
|
||||||
peer.LastErrorTime,
|
peer.LastErrorTime,
|
||||||
peer.KeyBytes,
|
peer.Key.GetPKIXPublicKeyBytes(),
|
||||||
peer.RootBytes,
|
peer.Root.GetPKIXPublicKeyBytes(),
|
||||||
peer.CoordsBytes,
|
peer.Coords.ConvertToByteSliсe(),
|
||||||
peer.Port,
|
peer.Port,
|
||||||
peer.Priority,
|
peer.Priority,
|
||||||
peer.RXBytes,
|
peer.RXBytes,
|
||||||
|
@ -182,9 +179,9 @@ func TestGetPeer(t *testing.T) {
|
||||||
|
|
||||||
rows := sqlmock.NewRows([]string{"up", "inbound", "last_error", "last_error_time", "coords",
|
rows := sqlmock.NewRows([]string{"up", "inbound", "last_error", "last_error_time", "coords",
|
||||||
"port", "priority", "Rxbytes", "Txbytes", "uptime", "latency", "uri", "key", "root"}).
|
"port", "priority", "Rxbytes", "Txbytes", "uptime", "latency", "uri", "key", "root"}).
|
||||||
AddRow(peer.Up, peer.Inbound, peer.PeerErr, peer.LastErrorTime, peer.CoordsBytes,
|
AddRow(peer.Up, peer.Inbound, peer.Error.GetErrorMessage(), peer.LastErrorTime, peer.Coords.ConvertToByteSliсe(),
|
||||||
peer.Port, peer.Priority, peer.RXBytes, peer.TXBytes, peer.Uptime, peer.Latency,
|
peer.Port, peer.Priority, peer.RXBytes, peer.TXBytes, peer.Uptime, peer.Latency,
|
||||||
peer.URI, peer.KeyBytes, peer.RootBytes)
|
peer.URI, peer.Key.GetPKIXPublicKeyBytes(), peer.Root.GetPKIXPublicKeyBytes())
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT (.+) FROM peer_infos WHERE Id = \\?").
|
mock.ExpectQuery("SELECT (.+) FROM peer_infos WHERE Id = \\?").
|
||||||
WithArgs(peer.Id).
|
WithArgs(peer.Id).
|
||||||
|
@ -247,8 +244,8 @@ func TestUpdatePeer(t *testing.T) {
|
||||||
WHERE
|
WHERE
|
||||||
Id = \?`).
|
Id = \?`).
|
||||||
WithArgs(
|
WithArgs(
|
||||||
peer.Up, peer.Inbound, peer.PeerErr, peer.LastErrorTime, peer.CoordsBytes, peer.Port, peer.Priority,
|
peer.Up, peer.Inbound, peer.Error.GetErrorMessage(), peer.LastErrorTime, peer.Coords.ConvertToByteSliсe(), peer.Port, peer.Priority,
|
||||||
peer.RXBytes, peer.TXBytes, peer.Uptime, peer.Latency, peer.URI, peer.KeyBytes, peer.RootBytes, peer.Id).
|
peer.RXBytes, peer.TXBytes, peer.Uptime, peer.Latency, peer.URI, peer.Key.GetPKIXPublicKeyBytes(), peer.Root.GetPKIXPublicKeyBytes(), peer.Id).
|
||||||
WillReturnResult(sqlmock.NewResult(1, 1))
|
WillReturnResult(sqlmock.NewResult(1, 1))
|
||||||
|
|
||||||
err = cfg.Update(peer)
|
err = cfg.Update(peer)
|
||||||
|
@ -297,7 +294,6 @@ func TestMain(t *testing.T) {
|
||||||
}
|
}
|
||||||
peer, err := core.NewPeerInfoDB(peerinfo)
|
peer, err := core.NewPeerInfoDB(peerinfo)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
root2PubKey, _, err := ed25519.GenerateKey(rand.Reader)
|
root2PubKey, _, err := ed25519.GenerateKey(rand.Reader)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
peerinfo2 := core.PeerInfo{
|
peerinfo2 := core.PeerInfo{
|
||||||
|
@ -318,7 +314,6 @@ func TestMain(t *testing.T) {
|
||||||
}
|
}
|
||||||
peer2, err := core.NewPeerInfoDB(peerinfo2)
|
peer2, err := core.NewPeerInfoDB(peerinfo2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = peerdb.Add(peer)
|
_, err = peerdb.Add(peer)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = peerdb.Add(peer2)
|
_, err = peerdb.Add(peer2)
|
||||||
|
@ -340,20 +335,40 @@ func TestMain(t *testing.T) {
|
||||||
|
|
||||||
require.Condition(t, condition, "Expected count to be 1", count)
|
require.Condition(t, condition, "Expected count to be 1", count)
|
||||||
|
|
||||||
peer2.Latency = 10
|
peer2.URI = "test"
|
||||||
|
peer2.Up = false
|
||||||
|
peer2.Inbound = false
|
||||||
|
peer2.Error.ParseMessage("Test")
|
||||||
|
peer2.LastErrorTime = sql.NullTime{}
|
||||||
|
peer2.Key.MarshalPKIXPublicKey(&root2PubKey)
|
||||||
|
peer2.Root.MarshalPKIXPublicKey(&pubkey)
|
||||||
|
peer2.Coords.ParseUint64Sliсe([]uint64{1, 1, 1, 1})
|
||||||
|
peer2.Port = 80
|
||||||
|
peer2.Priority = 2
|
||||||
peer2.RXBytes = 1024
|
peer2.RXBytes = 1024
|
||||||
peer2.TXBytes = 1024
|
peer2.TXBytes = 1024
|
||||||
peer2.Port = 80
|
peer2.Uptime = 1000
|
||||||
|
peer2.Latency = 10
|
||||||
err = peerdb.Update(peer2)
|
err = peerdb.Update(peer2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = peerdb.Get(peer2)
|
_, err = peerdb.Get(peer2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
condition = func() bool {
|
condition = func() bool {
|
||||||
return peer2.Latency == 10 &&
|
return peer2.URI == "test" &&
|
||||||
|
peer2.Up == false &&
|
||||||
|
peer2.Inbound == false &&
|
||||||
|
peer2.Error.GetErrorMessage() == "Test" &&
|
||||||
|
peer2.LastErrorTime.Time.IsZero() &&
|
||||||
|
peer2.Key.GetPKIXPublicKey().Equal(root2PubKey) &&
|
||||||
|
peer2.Root.GetPKIXPublicKey().Equal(pubkey) &&
|
||||||
|
reflect.DeepEqual(peer2.Coords.ConvertToUintSliсe(), []uint64{1, 1, 1, 1}) &&
|
||||||
|
peer2.Port == 80 &&
|
||||||
|
peer2.Priority == 2 &&
|
||||||
peer2.RXBytes == 2048 &&
|
peer2.RXBytes == 2048 &&
|
||||||
peer2.TXBytes == 3072 &&
|
peer2.TXBytes == 3072 &&
|
||||||
peer2.Port == 80 && peer2.URI == "new.test" && peer2.Key.Equal(pubkey)
|
peer2.Uptime == 4600 &&
|
||||||
|
peer2.Latency == 10
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Condition(t, condition, "Inner exception")
|
require.Condition(t, condition, "Inner exception")
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestSelectPathEntryInfo(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
rows := sqlmock.NewRows([]string{"Sequence", "Key", "Path"}).
|
rows := sqlmock.NewRows([]string{"Sequence", "Key", "Path"}).
|
||||||
AddRow(100, model.KeyBytes, model.PathBytes)
|
AddRow(100, model.Key.GetPKIXPublicKeyBytes(), model.Path.ConvertToByteSliсe())
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT (.+) FROM path_entry_info WHERE Id = \\?").
|
mock.ExpectQuery("SELECT (.+) FROM path_entry_info WHERE Id = \\?").
|
||||||
WithArgs(model.Id).
|
WithArgs(model.Id).
|
||||||
|
@ -72,8 +72,8 @@ func TestInsertPathEntryInfo(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
mock.ExpectExec("INSERT INTO path_entry_info").
|
mock.ExpectExec("INSERT INTO path_entry_info").
|
||||||
WithArgs(
|
WithArgs(
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.PathBytes,
|
model.Path.ConvertToByteSliсe(),
|
||||||
model.Sequence,
|
model.Sequence,
|
||||||
).
|
).
|
||||||
WillReturnResult(sqlmock.NewResult(1, 1))
|
WillReturnResult(sqlmock.NewResult(1, 1))
|
||||||
|
@ -145,8 +145,8 @@ func TestUpdatePathEntryInfo(t *testing.T) {
|
||||||
Id = \?`).
|
Id = \?`).
|
||||||
WithArgs(
|
WithArgs(
|
||||||
model.Sequence,
|
model.Sequence,
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.PathBytes,
|
model.Path.ConvertToByteSliсe(),
|
||||||
model.Id,
|
model.Id,
|
||||||
).WillReturnResult(sqlmock.NewResult(1, 1))
|
).WillReturnResult(sqlmock.NewResult(1, 1))
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ func TestSelectSelfInfo(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
rows := sqlmock.NewRows([]string{"RoutingEntries", "Key"}).
|
rows := sqlmock.NewRows([]string{"RoutingEntries", "Key"}).
|
||||||
AddRow(100, model.KeyBytes)
|
AddRow(100, model.Key.GetPKIXPublicKeyBytes())
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT (.+) FROM self_info WHERE Id = \\?").
|
mock.ExpectQuery("SELECT (.+) FROM self_info WHERE Id = \\?").
|
||||||
WithArgs(model.Id).
|
WithArgs(model.Id).
|
||||||
|
@ -68,7 +68,7 @@ func TestInsertSelfInfo(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
mock.ExpectExec("INSERT OR REPLACE INTO self_info").
|
mock.ExpectExec("INSERT OR REPLACE INTO self_info").
|
||||||
WithArgs(
|
WithArgs(
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.RoutingEntries,
|
model.RoutingEntries,
|
||||||
).
|
).
|
||||||
WillReturnResult(sqlmock.NewResult(1, 1))
|
WillReturnResult(sqlmock.NewResult(1, 1))
|
||||||
|
@ -136,7 +136,7 @@ func TestUpdateSelfInfo(t *testing.T) {
|
||||||
Id = \?`).
|
Id = \?`).
|
||||||
WithArgs(
|
WithArgs(
|
||||||
model.RoutingEntries,
|
model.RoutingEntries,
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.Id,
|
model.Id,
|
||||||
).WillReturnResult(sqlmock.NewResult(1, 1))
|
).WillReturnResult(sqlmock.NewResult(1, 1))
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ func TestSelectSessionInfo(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
rows := sqlmock.NewRows([]string{"RXBytes", "TXBytes", "Duration", "Key"}).
|
rows := sqlmock.NewRows([]string{"RXBytes", "TXBytes", "Duration", "Key"}).
|
||||||
AddRow(100, 200, 100, model.KeyBytes)
|
AddRow(100, 200, 100, model.Key.GetPKIXPublicKeyBytes())
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT (.+) FROM session_info WHERE Id = \\?").
|
mock.ExpectQuery("SELECT (.+) FROM session_info WHERE Id = \\?").
|
||||||
WithArgs(model.Id).
|
WithArgs(model.Id).
|
||||||
|
@ -75,7 +75,7 @@ func TestInsertSessionInfo(t *testing.T) {
|
||||||
|
|
||||||
mock.ExpectExec("INSERT INTO session_info").
|
mock.ExpectExec("INSERT INTO session_info").
|
||||||
WithArgs(
|
WithArgs(
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.RXBytes,
|
model.RXBytes,
|
||||||
model.TXBytes,
|
model.TXBytes,
|
||||||
model.Uptime,
|
model.Uptime,
|
||||||
|
@ -154,7 +154,7 @@ func TestUpdateSessionInfo(t *testing.T) {
|
||||||
model.RXBytes,
|
model.RXBytes,
|
||||||
model.TXBytes,
|
model.TXBytes,
|
||||||
model.Uptime,
|
model.Uptime,
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.Id,
|
model.Id,
|
||||||
).WillReturnResult(sqlmock.NewResult(1, 1))
|
).WillReturnResult(sqlmock.NewResult(1, 1))
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestSelectTreeEntryInfo(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
rows := sqlmock.NewRows([]string{"Sequence", "Key", "Parent"}).
|
rows := sqlmock.NewRows([]string{"Sequence", "Key", "Parent"}).
|
||||||
AddRow(100, model.KeyBytes, model.ParentBytes)
|
AddRow(100, model.Key.GetPKIXPublicKeyBytes(), model.Parent.GetPKIXPublicKeyBytes())
|
||||||
|
|
||||||
mock.ExpectQuery("SELECT (.+) FROM tree_entry_info WHERE Id = \\?").
|
mock.ExpectQuery("SELECT (.+) FROM tree_entry_info WHERE Id = \\?").
|
||||||
WithArgs(model.Id).
|
WithArgs(model.Id).
|
||||||
|
@ -73,8 +73,8 @@ func TestInsertTreeEntryInfo(t *testing.T) {
|
||||||
|
|
||||||
mock.ExpectExec("INSERT INTO tree_entry_info").
|
mock.ExpectExec("INSERT INTO tree_entry_info").
|
||||||
WithArgs(
|
WithArgs(
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.ParentBytes,
|
model.Parent.GetPKIXPublicKeyBytes(),
|
||||||
model.Sequence,
|
model.Sequence,
|
||||||
).
|
).
|
||||||
WillReturnResult(sqlmock.NewResult(1, 1))
|
WillReturnResult(sqlmock.NewResult(1, 1))
|
||||||
|
@ -146,8 +146,8 @@ func TestUpdateTreeEntryInfo(t *testing.T) {
|
||||||
Id = \?`).
|
Id = \?`).
|
||||||
WithArgs(
|
WithArgs(
|
||||||
model.Sequence,
|
model.Sequence,
|
||||||
model.KeyBytes,
|
model.Key.GetPKIXPublicKeyBytes(),
|
||||||
model.ParentBytes,
|
model.Parent.GetPKIXPublicKeyBytes(),
|
||||||
model.Id,
|
model.Id,
|
||||||
).WillReturnResult(sqlmock.NewResult(1, 1))
|
).WillReturnResult(sqlmock.NewResult(1, 1))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue