Documentation ¶
Overview ¶
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/.
Index ¶
- func FromStrpairMap(m strpair.Map) []*pb.StringPair
- func InvocationArtifactName(invocationID, artifactID string) string
- func InvocationName(id string) string
- func MustDuration(du *durationpb.Duration) time.Duration
- func MustTimestamp(ts *tspb.Timestamp) time.Time
- func MustTimestampProto(t time.Time) *tspb.Timestamp
- func NormalizeInvocation(inv *pb.Invocation)
- func NormalizeTestResult(tr *pb.TestResult)
- func NormalizeTestResultSlice(trs []*pb.TestResult)
- func ParseArtifactName(name string) (invocationID, testID, resultID, artifactID string, err error)
- func ParseInvocationName(name string) (id string, err error)
- func ParseTestExonerationName(name string) (invocationID, testID, exonerationID string, err error)
- func ParseTestResultName(name string) (invID, testID, resultID string, err error)
- func Query(ctx context.Context, dest chan<- proto.Message, client pb.ResultDBClient, ...) error
- func SortStringPairs(tags []*pb.StringPair)
- func SortedVariantKeys(vr *pb.Variant) []string
- func StringPair(k, v string) *pb.StringPair
- func StringPairFromString(s string) (*pb.StringPair, error)
- func StringPairToString(pair *pb.StringPair) string
- func StringPairs(pairs ...string) []*pb.StringPair
- func StringPairsContain(pairs []*pb.StringPair, item *pb.StringPair) bool
- func StringPairsToStrings(pairs ...*pb.StringPair) []string
- func TestExonerationName(invocationID, testID, exonerationID string) string
- func TestResultArtifactName(invocationID, testID, resulID, artifactID string) string
- func TestResultName(invID, testID, resultID string) string
- func ValidateArtifactID(id string) error
- func ValidateArtifactName(name string) error
- func ValidateArtifactPredicate(p *pb.ArtifactPredicate) error
- func ValidateBatchRequestCount(count int) error
- func ValidateBigQueryExport(bqExport *pb.BigQueryExport) error
- func ValidateEnum(value int32, validValues map[int32]string) error
- func ValidateFilePath(path string) error
- func ValidateInvocationID(id string) error
- func ValidateInvocationName(name string) error
- func ValidateRequestID(requestID string) error
- func ValidateResultID(resultID string) error
- func ValidateStartTimeWithDuration(now time.Time, startTime *tspb.Timestamp, duration *dpb.Duration) error
- func ValidateStringPair(p *pb.StringPair) error
- func ValidateStringPairs(pairs []*pb.StringPair) error
- func ValidateSummaryHTML(summary string) error
- func ValidateTestExonerationName(name string) error
- func ValidateTestExonerationPredicate(p *pb.TestExonerationPredicate) error
- func ValidateTestID(testID string) error
- func ValidateTestLocation(loc *pb.TestLocation) error
- func ValidateTestMetadata(tmd *pb.TestMetadata) error
- func ValidateTestResult(now time.Time, msg *pb.TestResult) (err error)
- func ValidateTestResultName(name string) error
- func ValidateTestResultPredicate(p *pb.TestResultPredicate) error
- func ValidateTestResultStatus(s pb.TestStatus) error
- func ValidateVariant(vr *pb.Variant) error
- func ValidateVariantPredicate(p *pb.VariantPredicate) error
- func Variant(pairs ...string) *pb.Variant
- func VariantFromStrings(pairs []string) (*pb.Variant, error)
- func VariantHash(vr *pb.Variant) string
- func VariantToStringPairs(vr *pb.Variant) []*pb.StringPair
- func VariantToStrings(vr *pb.Variant) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromStrpairMap ¶
func FromStrpairMap(m strpair.Map) []*pb.StringPair
FromStrpairMap converts a strpair.Map to []*pb.StringPair.
func InvocationArtifactName ¶
InvocationArtifactName synthesizes a name of an invocation-level artifact. Does not validate IDs, use ValidateInvocationID and ValidateArtifactID.
func InvocationName ¶
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 ¶
MustTimestamp converts a *tspb.Timestamp to a time.Time and panics on failure.
func MustTimestampProto ¶
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 ¶
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 ¶
ParseInvocationName extracts the invocation id.
func ParseTestExonerationName ¶
ParseTestExonerationName extracts invocation, test id and exoneration IDs from the name.
func ParseTestResultName ¶
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 ¶
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 ¶
TestExonerationName synthesizes a test exoneration name. Assumes invocation and exoneration IDs are valid.
func TestResultArtifactName ¶
TestResultArtifactName synthesizes a name of an test-result-level artifact. Does not validate IDs, use ValidateInvocationID, ValidateTestID, ValidateResultID and ValidateArtifactID.
func TestResultName ¶
TestResultName synthesizes a test result name from its parts. Does not validate parts; use ValidateTestResultName.
func ValidateArtifactID ¶
ValidateArtifactID returns a non-nil error if id is invalid.
func ValidateArtifactName ¶
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 ¶
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 ¶
ValidateEnum returns a non-nil error if the value is not among valid values.
func ValidateFilePath ¶
ValidateFilePath returns a non-nil error if path is invalid.
func ValidateInvocationID ¶
ValidateInvocationID returns a non-nil error if id is invalid.
func ValidateInvocationName ¶
ValidateInvocationName returns a non-nil error if name is invalid.
func ValidateRequestID ¶
ValidateRequestID returns a non-nil error if requestID is invalid. Returns nil if requestID is empty.
func ValidateResultID ¶
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 ¶
ValidateSummaryHTML returns a non-nil error if summary is invalid.
func ValidateTestExonerationName ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
VariantToStrings returns a key:val string slice representation of the Variant. Never returns nil.
Types ¶
This section is empty.