github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/api/query/cache/backfill/backfill_test.go (about) 1 //go:build small 2 // +build small 3 4 // Copyright 2018 The WPT Dashboard Project. All rights reserved. 5 // Use of this source code is governed by a BSD-style license that can be 6 // found in the LICENSE file. 7 8 package backfill 9 10 import ( 11 "errors" 12 "testing" 13 14 gomock "github.com/golang/mock/gomock" 15 "github.com/stretchr/testify/assert" 16 "github.com/web-platform-tests/wpt.fyi/api/query/cache/index" 17 "github.com/web-platform-tests/wpt.fyi/shared/sharedtest" 18 ) 19 20 func TestNilIndex(t *testing.T) { 21 ctrl := gomock.NewController(t) 22 defer ctrl.Finish() 23 store := sharedtest.NewMockDatastore(ctrl) 24 _, err := FillIndex(store, nil, nil, 1, uint(10), uint64(1), 0.0, nil) 25 assert.Equal(t, errNilIndex, err) 26 } 27 28 func TestFetchErr(t *testing.T) { 29 ctrl := gomock.NewController(t) 30 defer ctrl.Finish() 31 store := sharedtest.NewMockDatastore(ctrl) 32 query := sharedtest.NewMockTestRunQuery(ctrl) 33 idx := index.NewMockIndex(ctrl) 34 expected := errors.New("Fetch error") 35 store.EXPECT().TestRunQuery().Return(query) 36 query.EXPECT().LoadTestRuns(gomock.Any(), nil, nil, nil, nil, gomock.Any(), nil).Return(nil, expected) 37 _, err := FillIndex(store, nil, nil, 1, uint(10), uint64(1), 0.0, idx) 38 assert.Equal(t, expected, err) 39 }