Debian Codegraph @

bazel/exporter/util_test.go

raw
1 // Copyright 2022 Google LLC
2 //
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 package exporter
7
8 import (
9 "go.skia.org/infra/go/skerr"
10 "go.skia.org/skia/bazel/exporter/build_proto/analysis_v2"
11 "go.skia.org/skia/bazel/exporter/build_proto/build"
12 "google.golang.org/protobuf/encoding/prototext"
13 "google.golang.org/protobuf/proto"
14 )
15
16 // A test helper function to convert a textproto protobuf into a binary protobuf.
17 func textProtoToProtobuf(textProto string) ([]byte, error) {
18 qr := analysis_v2.CqueryResult{}
19 err := prototext.Unmarshal([]byte(textProto), &qr)
20 if err != nil {
21 return nil, skerr.Wrapf(err, "unable to unmarshal textproto")
22 }
23
24 return proto.Marshal(&qr)
25 }
26
27 // A test helper function to create a build.Rule with given properties (and srcs).
28 func createTestBuildRule(name, ruleClass, loc string, srcs []string) *build.Rule {
29 srcsAttrName := "srcs"
30 ad := build.Attribute_STRING_LIST
31 attr := build.Attribute{Name: &srcsAttrName, Type: &ad, StringListValue: srcs}
32
33 r := build.Rule{Name: &name, RuleClass: &ruleClass, Location: &loc}
34 r.Attribute = append(r.Attribute, &attr)
35 return &r
36 }