go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/buildbucket/cmd/bbagent/bbinput/input_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 bbinput
    16  
    17  import (
    18  	"testing"
    19  
    20  	bbpb "go.chromium.org/luci/buildbucket/proto"
    21  
    22  	. "github.com/smartystreets/goconvey/convey"
    23  	. "go.chromium.org/luci/common/testing/assertions"
    24  )
    25  
    26  func TestInputOK(t *testing.T) {
    27  	tests := []struct {
    28  		name   string
    29  		input  string
    30  		expect *bbpb.BBAgentArgs
    31  	}{
    32  		{"basic", "eJwDAAAAAAE", &bbpb.BBAgentArgs{}},
    33  		{"stuff", "eJxTElzEyFeSkVmsAESJCiWpxSUANZQF+g", &bbpb.BBAgentArgs{
    34  			Build: &bbpb.Build{
    35  				SummaryMarkdown: "this is a test",
    36  			},
    37  		}},
    38  	}
    39  
    40  	Convey(`Parse (ok)`, t, func() {
    41  		for _, tc := range tests {
    42  			Convey(tc.name, func() {
    43  				ret, err := Parse(tc.input)
    44  				So(err, ShouldBeNil)
    45  				So(ret, ShouldResembleProto, tc.expect)
    46  			})
    47  		}
    48  	})
    49  }
    50  
    51  func TestInputBad(t *testing.T) {
    52  	t.Parallel()
    53  
    54  	tests := []struct {
    55  		name   string
    56  		input  string
    57  		expect string
    58  	}{
    59  		{"empty", "", "inputs required"},
    60  		{"base64", "!!", "decoding base64"},
    61  		{"zlib", "\n", "opening zlib reader"},
    62  		{"decompress", "eJwXAAAAAAE", "decompressing zlib"},
    63  		{"proto", "eJxLSswDQgAITwJi", "parsing proto"},
    64  	}
    65  
    66  	Convey(`Parse (err)`, t, func() {
    67  		for _, tc := range tests {
    68  			Convey(tc.name, func() {
    69  				_, err := Parse(tc.input)
    70  				So(err, ShouldErrLike, tc.expect)
    71  			})
    72  		}
    73  	})
    74  }