github.com/GoogleCloudPlatform/testgrid@v0.0.174/resultstore/client_test.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package resultstore 18 19 import ( 20 "testing" 21 "time" 22 23 resultstore "google.golang.org/genproto/googleapis/devtools/resultstore/v2" 24 ) 25 26 func TestConvertToInvocations(t *testing.T) { 27 // Resultstore stores time using the protobuf type. It differs from the 28 // Golang's Time and Duration type and requires conversion. 29 now := stamp(time.Now()) 30 duration := dur(time.Second) 31 cases := []struct { 32 name string 33 response *resultstore.SearchInvocationsResponse 34 expected []*Invocation 35 }{ 36 { 37 name: "empty response", 38 response: &resultstore.SearchInvocationsResponse{}, 39 expected: []*Invocation{}, 40 }, 41 { 42 name: "single response", 43 response: &resultstore.SearchInvocationsResponse{ 44 Invocations: []*resultstore.Invocation{ 45 { 46 Name: "invocations/fakeid-12345", 47 Id: &resultstore.Invocation_Id{ 48 InvocationId: "fakeid-12345", 49 }, 50 StatusAttributes: &resultstore.StatusAttributes{ 51 Status: resultstore.Status_PASSED, 52 }, 53 Timing: &resultstore.Timing{ 54 StartTime: now, 55 Duration: duration, 56 }, 57 }, 58 }, 59 }, 60 expected: []*Invocation{ 61 { 62 Name: "invocations/fakeid-12345", 63 Duration: protoDurationToGoDuration(duration), 64 Start: protoTimeToGoTime(now), 65 Status: resultstore.Status_PASSED, 66 }, 67 }, 68 }, 69 } 70 71 for _, tc := range cases { 72 t.Run(tc.name, func(t *testing.T) { 73 got := convertToInvocations(tc.response) 74 if !deepEqual(got, tc.expected) { 75 t.Errorf(diff(got, tc.expected)) 76 } 77 }) 78 } 79 }