Package pbutil implements utility functions for ResultDB protobuf messages.

TODO(nodir): many of these functions are not hardly useful for clients, e.g. ones involved in request validation. The request validation functions themselves are not in this package. Ideally all symbols in this package are useful for others. Otherwise pbutil should be in internal/.



This section is empty.


This section is empty.


func FromStrpairMap

func FromStrpairMap(m strpair.Map) []*pb.StringPair

FromStrpairMap converts a strpair.Map to []*pb.StringPair.

func InvocationArtifactName

func InvocationArtifactName(invocationID, artifactID string) string

InvocationArtifactName synthesizes a name of an invocation-level artifact. Does not validate IDs, use ValidateInvocationID and ValidateArtifactID.

func InvocationName

func InvocationName(id string) string

InvocationName synthesizes an invocation name from an id. Does not validate id, use ValidateInvocationID.

func MustDuration

func MustDuration(du *durationpb.Duration) time.Duration

MustDuration converts a *durationpb.Duration to a time.Duration and panics on failure.

func MustTimestamp

func MustTimestamp(ts *tspb.Timestamp) time.Time

MustTimestamp converts a *tspb.Timestamp to a time.Time and panics on failure.

func MustTimestampProto

func MustTimestampProto(t time.Time) *tspb.Timestamp

MustTimestampProto converts a time.Time to a *tspb.Timestamp and panics on failure.

func NormalizeInvocation

func NormalizeInvocation(inv *pb.Invocation)

NormalizeInvocation converts inv to the canonical form.

func NormalizeTestResult

func NormalizeTestResult(tr *pb.TestResult)

NormalizeTestResult converts inv to the canonical form.

func NormalizeTestResultSlice

func NormalizeTestResultSlice(trs []*pb.TestResult)

NormalizeTestResultSlice converts trs to the canonical form.

func ParseArtifactName

func ParseArtifactName(name string) (invocationID, testID, resultID, artifactID string, err error)

ParseArtifactName extracts the invocation ID, unescaped test id, result ID and artifact ID. The testID and resultID are empty if this is an invocation-level artifact.

func ParseInvocationName

func ParseInvocationName(name string) (id string, err error)

ParseInvocationName extracts the invocation id.

func ParseTestExonerationName

func ParseTestExonerationName(name string) (invocationID, testID, exonerationID string, err error)

ParseTestExonerationName extracts invocation, test id and exoneration IDs from the name.

func ParseTestResultName

func ParseTestResultName(name string) (invID, testID, resultID string, err error)

ParseTestResultName extracts the invocation ID, unescaped test id, and result ID.

func Query

func Query(ctx context.Context, dest chan<- proto.Message, client pb.ResultDBClient, reqs ...proto.Message) error

Query queries for results continuously, sending individual items to dest channel until the paging query is exhausted or the context is canceled. A request must be *pb.QueryTestResultRequest, pb.QueryTestExonerationsRequest or *pb.QueryArtifactsRequest. Messages sent to dest are *pb.TestResult, *pb.TestExoneration or *pb.Artifact respectively.

Does not return the next page token because ctx can be canceled in the middle of a page.

If there are multiple requests in reqs, then runs them all concurrently and sends all of their results to dest. This is useful to query items of different types, e.g. test results and test exonerations. Does not limit concurrency.

func SortStringPairs

func SortStringPairs(tags []*pb.StringPair)

SortStringPairs sorts in-place the tags slice lexicographically by key, then value.

func SortedVariantKeys

func SortedVariantKeys(vr *pb.Variant) []string

SortedVariantKeys returns the keys in the variant as a sorted slice.

func StringPair

func StringPair(k, v string) *pb.StringPair

StringPair creates a pb.StringPair with the given strings as key/value field values.

func StringPairFromString

func StringPairFromString(s string) (*pb.StringPair, error)

StringPairFromString creates a pb.StringPair from the given key:val string.

func StringPairToString

func StringPairToString(pair *pb.StringPair) string

StringPairToString converts a StringPair to a key:val string.

func StringPairs

func StringPairs(pairs ...string) []*pb.StringPair

StringPairs creates a slice of pb.StringPair from a list of strings alternating key/value.

Panics if an odd number of tokens is passed.

func StringPairsContain

func StringPairsContain(pairs []*pb.StringPair, item *pb.StringPair) bool

StringPairsContain checks if item is present in pairs.

func StringPairsToStrings

func StringPairsToStrings(pairs ...*pb.StringPair) []string

StringPairsToStrings converts pairs to a slice of "{key}:{value}" strings in the same order.

func TestExonerationName

func TestExonerationName(invocationID, testID, exonerationID string) string

TestExonerationName synthesizes a test exoneration name. Assumes invocation and exoneration IDs are valid.

func TestResultArtifactName

func TestResultArtifactName(invocationID, testID, resulID, artifactID string) string

TestResultArtifactName synthesizes a name of an test-result-level artifact. Does not validate IDs, use ValidateInvocationID, ValidateTestID, ValidateResultID and ValidateArtifactID.

func TestResultName

func TestResultName(invID, testID, resultID string) string

TestResultName synthesizes a test result name from its parts. Does not validate parts; use ValidateTestResultName.

func ValidateArtifactID

func ValidateArtifactID(id string) error

ValidateArtifactID returns a non-nil error if id is invalid.

func ValidateArtifactName

func ValidateArtifactName(name string) error

ValidateArtifactName returns a non-nil error if name is invalid.

func ValidateArtifactPredicate

func ValidateArtifactPredicate(p *pb.ArtifactPredicate) error

ValidateArtifactPredicate returns a non-nil error if p is determined to be invalid.

func ValidateBatchRequestCount

func ValidateBatchRequestCount(count int) error

ValidateBatchRequestCount validates the number of requests in a batch request.

func ValidateBigQueryExport

func ValidateBigQueryExport(bqExport *pb.BigQueryExport) error

ValidateBigQueryExport returns a non-nil error if bqExport is determined to be invalid.

func ValidateEnum

func ValidateEnum(value int32, validValues map[int32]string) error

ValidateEnum returns a non-nil error if the value is not among valid values.

func ValidateFilePath

func ValidateFilePath(path string) error

ValidateFilePath returns a non-nil error if path is invalid.

func ValidateInvocationID

func ValidateInvocationID(id string) error

ValidateInvocationID returns a non-nil error if id is invalid.

func ValidateInvocationName

func ValidateInvocationName(name string) error

ValidateInvocationName returns a non-nil error if name is invalid.

func ValidateRequestID

func ValidateRequestID(requestID string) error

ValidateRequestID returns a non-nil error if requestID is invalid. Returns nil if requestID is empty.

func ValidateResultID

func ValidateResultID(resultID string) error

ValidateTestResultID returns a non-nil error if resultID is invalid.

func ValidateStartTimeWithDuration

func ValidateStartTimeWithDuration(now time.Time, startTime *tspb.Timestamp, duration *dpb.Duration) error

ValidateStartTimeWithDuration returns a non-nil error if startTime and duration are invalid.

func ValidateStringPair

func ValidateStringPair(p *pb.StringPair) error

ValidateStringPair returns an error if p is invalid.

func ValidateStringPairs

func ValidateStringPairs(pairs []*pb.StringPair) error

ValidateStringPairs returns an error if any of the pairs is invalid.

func ValidateSummaryHTML

func ValidateSummaryHTML(summary string) error

ValidateSummaryHTML returns a non-nil error if summary is invalid.

func ValidateTestExonerationName

func ValidateTestExonerationName(name string) error

ValidateTestExonerationName returns a non-nil error if the test exoneration name is invalid.

func ValidateTestExonerationPredicate

func ValidateTestExonerationPredicate(p *pb.TestExonerationPredicate) error

ValidateTestExonerationPredicate returns a non-nil error if p is determined to be invalid.

func ValidateTestID

func ValidateTestID(testID string) error

ValidateTestID returns a non-nil error if testID is invalid.

func ValidateTestLocation

func ValidateTestLocation(loc *pb.TestLocation) error

ValidateTestLocation returns a non-nil error if loc is invalid.

func ValidateTestMetadata

func ValidateTestMetadata(tmd *pb.TestMetadata) error

ValidateTestMetadata returns a non-nil error if tmd is invalid.

func ValidateTestResult

func ValidateTestResult(now time.Time, msg *pb.TestResult) (err error)

ValidateTestResult returns a non-nil error if msg is invalid.

func ValidateTestResultName

func ValidateTestResultName(name string) error

ValidateTestResultName returns a non-nil error if name is invalid.

func ValidateTestResultPredicate

func ValidateTestResultPredicate(p *pb.TestResultPredicate) error

ValidateTestResultPredicate returns a non-nil error if p is determined to be invalid.

func ValidateTestResultStatus

func ValidateTestResultStatus(s pb.TestStatus) error

ValidateTestResultStatus returns a non-nil error if s is invalid for a test result.

func ValidateVariant

func ValidateVariant(vr *pb.Variant) error

ValidateVariant returns an error if vr is invalid.

func ValidateVariantPredicate

func ValidateVariantPredicate(p *pb.VariantPredicate) error

ValidateVariantPredicate returns a non-nil error if p is determined to be invalid.

func Variant

func Variant(pairs ...string) *pb.Variant

Variant creates a pb.Variant from a list of strings alternating key/value. Does not validate pairs. See also VariantFromStrings.

Panics if an odd number of tokens is passed.

func VariantFromStrings

func VariantFromStrings(pairs []string) (*pb.Variant, error)

VariantFromStrings returns a Variant proto given the key:val string slice of its contents.

If a key appears multiple times, the last pair wins.

func VariantHash

func VariantHash(vr *pb.Variant) string

VariantHash returns a short hash of the variant.

func VariantToStringPairs

func VariantToStringPairs(vr *pb.Variant) []*pb.StringPair

VariantToStringPairs returns a slice of StringPair derived from *pb.Variant.

func VariantToStrings

func VariantToStrings(vr *pb.Variant) []string

VariantToStrings returns a key:val string slice representation of the Variant. Never returns nil.


This section is empty.