Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Go tests in MySQL storage implementation #110

Merged
merged 12 commits into from
Aug 7, 2024
Merged
15 changes: 14 additions & 1 deletion storage/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bytes"
"context"
"database/sql"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -56,6 +57,7 @@ type Storage struct {
}

// New creates a new instance of the MySQL-based Storage.
// Note that `tessera.WithCheckpointSignerVerifier()` is mandatory in the `opts` argument.
func New(ctx context.Context, db *sql.DB, opts ...func(*tessera.StorageOptions)) (*Storage, error) {
opt := tessera.ResolveStorageOptions(&tessera.StorageOptions{
BatchMaxAge: defaultQueueMaxAge,
Expand All @@ -70,6 +72,9 @@ func New(ctx context.Context, db *sql.DB, opts ...func(*tessera.StorageOptions))
klog.Errorf("Failed to ping database: %v", err)
return nil, err
}
if s.newCheckpoint == nil || s.parseCheckpoint == nil {
roger2hk marked this conversation as resolved.
Show resolved Hide resolved
return nil, errors.New("tessera.WithCheckpointSignerVerifier must be provided in New()")
}

s.queue = storage.NewQueue(ctx, opt.BatchMaxAge, opt.BatchMaxSize, s.sequenceBatch)

Expand Down Expand Up @@ -187,7 +192,15 @@ func (s *Storage) ReadEntryBundle(ctx context.Context, index uint64) ([]byte, er
}

var entryBundle []byte
return entryBundle, row.Scan(&entryBundle)
if err := row.Scan(&entryBundle); err != nil {
if err == sql.ErrNoRows {
return nil, nil
}

return nil, err
}

return entryBundle, nil
}

func (s *Storage) writeEntryBundle(ctx context.Context, tx *sql.Tx, index uint64, entryBundle []byte) error {
Expand Down
Loading
Loading