go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/swarming/server/bq/state_test.go (about) 1 // Copyright 2023 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 bq 16 17 import ( 18 "context" 19 "testing" 20 21 "google.golang.org/protobuf/types/known/durationpb" 22 "google.golang.org/protobuf/types/known/timestamppb" 23 24 "go.chromium.org/luci/common/clock/testclock" 25 "go.chromium.org/luci/gae/impl/memory" 26 "go.chromium.org/luci/gae/service/datastore" 27 28 "go.chromium.org/luci/swarming/server/bq/taskspb" 29 30 . "github.com/smartystreets/goconvey/convey" 31 ) 32 33 func TestExportState(t *testing.T) { 34 t.Parallel() 35 Convey("With mocks", t, func() { 36 setup := func() (context.Context, testclock.TestClock) { 37 ctx, tc := testclock.UseTime(context.Background(), testclock.TestRecentTimeUTC) 38 ctx = memory.Use(ctx) 39 return ctx, tc 40 } 41 Convey("Can create export state key from CreateExportTask", func() { 42 ctx, _ := setup() 43 task := &taskspb.CreateExportTask{ 44 CloudProject: "foo", 45 Dataset: "bar", 46 TableName: "baz", 47 Start: timestamppb.New(testclock.TestRecentTimeUTC), 48 Duration: durationpb.New(100), 49 } 50 state := ExportState{ 51 Key: exportStateKey(ctx, task), 52 WriteStreamName: "stream", 53 } 54 err := datastore.Put(ctx, &state) 55 So(err, ShouldBeNil) 56 }) 57 }) 58 }