go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/pbutil/invocation_processing_test.go (about)

     1  // Copyright 2019 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package pbutil
    16  
    17  import (
    18  	"testing"
    19  
    20  	pb "go.chromium.org/luci/resultdb/proto/v1"
    21  
    22  	. "github.com/smartystreets/goconvey/convey"
    23  	. "go.chromium.org/luci/common/testing/assertions"
    24  )
    25  
    26  func TestValidateBigQueryExport(t *testing.T) {
    27  	Convey(`ValidateBigQueryExport`, t, func() {
    28  		Convey(`Valid, Empty TestResults`, func() {
    29  			err := ValidateBigQueryExport(&pb.BigQueryExport{
    30  				Project: "project",
    31  				Dataset: "dataset",
    32  				Table:   "table",
    33  				ResultType: &pb.BigQueryExport_TestResults_{
    34  					TestResults: &pb.BigQueryExport_TestResults{},
    35  				},
    36  			})
    37  			So(err, ShouldBeNil)
    38  		})
    39  
    40  		Convey(`Missing project`, func() {
    41  			err := ValidateBigQueryExport(&pb.BigQueryExport{
    42  				Dataset: "dataset",
    43  				Table:   "table",
    44  			})
    45  			So(err, ShouldErrLike, `project: unspecified`)
    46  		})
    47  
    48  		Convey(`Missing dataset`, func() {
    49  			err := ValidateBigQueryExport(&pb.BigQueryExport{
    50  				Project: "project",
    51  				Table:   "table",
    52  			})
    53  			So(err, ShouldErrLike, `dataset: unspecified`)
    54  		})
    55  
    56  		Convey(`Missing table`, func() {
    57  			err := ValidateBigQueryExport(&pb.BigQueryExport{
    58  				Project: "project",
    59  				Dataset: "dataset",
    60  			})
    61  			So(err, ShouldErrLike, `table: unspecified`)
    62  		})
    63  
    64  		Convey(`Missing ResultType`, func() {
    65  			err := ValidateBigQueryExport(&pb.BigQueryExport{
    66  				Project: "project",
    67  				Dataset: "dataset",
    68  				Table:   "table",
    69  			})
    70  			So(err, ShouldErrLike, `result_type: unspecified`)
    71  		})
    72  
    73  		Convey(`invalid test result predicate`, func() {
    74  			err := ValidateBigQueryExport(&pb.BigQueryExport{
    75  				Project: "project",
    76  				Dataset: "dataset",
    77  				Table:   "table",
    78  				ResultType: &pb.BigQueryExport_TestResults_{
    79  					TestResults: &pb.BigQueryExport_TestResults{
    80  						Predicate: &pb.TestResultPredicate{
    81  							TestIdRegexp: "(",
    82  						},
    83  					},
    84  				},
    85  			})
    86  			So(err, ShouldErrLike, `test_results: predicate`)
    87  		})
    88  
    89  		Convey(`invalid artifact predicate`, func() {
    90  			err := ValidateBigQueryExport(&pb.BigQueryExport{
    91  				Project: "project",
    92  				Dataset: "dataset",
    93  				Table:   "table",
    94  				ResultType: &pb.BigQueryExport_TextArtifacts_{
    95  					TextArtifacts: &pb.BigQueryExport_TextArtifacts{
    96  						Predicate: &pb.ArtifactPredicate{
    97  							TestResultPredicate: &pb.TestResultPredicate{
    98  								TestIdRegexp: "(",
    99  							},
   100  						},
   101  					},
   102  				},
   103  			})
   104  			So(err, ShouldErrLike, `artifacts: predicate`)
   105  		})
   106  	})
   107  }