github.com/google/trillian-examples@v0.0.0-20240520080811-0d40d35cef0e/experimental/batchmap/sumdb/build/pipeline/entries_test.go (about) 1 // Copyright 2020 Google LLC. All Rights Reserved. 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 pipeline 16 17 import ( 18 "testing" 19 20 "github.com/apache/beam/sdks/v2/go/pkg/beam" 21 "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/passert" 22 "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/ptest" 23 ) 24 25 func TestMain(m *testing.M) { 26 ptest.Main(m) 27 } 28 29 func TestCreateEntries(t *testing.T) { 30 tests := []struct { 31 name string 32 treeID int64 33 metadata []Metadata 34 35 wantCount int 36 }{ 37 { 38 name: "single entry has 2 outputs", 39 treeID: 12345, 40 metadata: []Metadata{ 41 { 42 Module: "foo", 43 Version: "1", 44 RepoHash: "abcdefab", 45 ModHash: "deadbeef", 46 }, 47 }, 48 wantCount: 2, 49 }, 50 } 51 52 for _, test := range tests { 53 test := test 54 t.Run(test.name, func(t *testing.T) { 55 p, s := beam.NewPipelineWithRoot() 56 metadata := beam.CreateList(s, test.metadata) 57 58 entries := CreateEntries(s, test.treeID, metadata) 59 60 passert.Count(s, entries, "entries", test.wantCount) 61 err := ptest.Run(p) 62 if err != nil { 63 t.Errorf("unexpected error: %v", err) 64 } 65 }) 66 } 67 }