Skip to content

Commit

Permalink
Merge pull request #1705 from authzed/expose-revision-parser-helper
Browse files Browse the repository at this point in the history
expose revision parsing function for tests
  • Loading branch information
vroldanbet authored Jan 9, 2024
2 parents 73fdc79 + 650c4f5 commit 5a94656
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions pkg/datastore/revisionparsing/revisionparsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@ import (
"github.com/authzed/spicedb/internal/datastore/postgres"
"github.com/authzed/spicedb/internal/datastore/revisions"
"github.com/authzed/spicedb/internal/datastore/spanner"
"github.com/authzed/spicedb/pkg/datastore"
)

// ParsingFunc is a function that can parse a string into a revision.
type ParsingFunc func(revisionStr string) (rev datastore.Revision, err error)

// ParseRevisionStringByDatastoreEngineID defines a map from datastore engine ID to its associated
// revision parsing function.
var ParseRevisionStringByDatastoreEngineID = map[string]revisions.ParsingFunc{
memdb.Engine: memdb.ParseRevisionString,
crdb.Engine: crdb.ParseRevisionString,
postgres.Engine: postgres.ParseRevisionString,
mysql.Engine: mysql.ParseRevisionString,
spanner.Engine: spanner.ParseRevisionString,
var ParseRevisionStringByDatastoreEngineID = map[string]ParsingFunc{
memdb.Engine: ParsingFunc(memdb.ParseRevisionString),
crdb.Engine: ParsingFunc(crdb.ParseRevisionString),
postgres.Engine: ParsingFunc(postgres.ParseRevisionString),
mysql.Engine: ParsingFunc(mysql.ParseRevisionString),
spanner.Engine: ParsingFunc(spanner.ParseRevisionString),
}

// MustParseRevisionForTest is a convenience ParsingFunc that can be used in tests and panics when parsing an error.
func MustParseRevisionForTest(revisionStr string) (rev datastore.Revision) {
rev, err := testParser(revisionStr)
if err != nil {
panic(err)
}

return rev
}

var testParser = revisions.RevisionParser(revisions.HybridLogicalClock)

0 comments on commit 5a94656

Please sign in to comment.