go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/scheduler/appengine/presentation/state_test.go (about) 1 // Copyright 2017 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 presentation 16 17 import ( 18 "context" 19 "testing" 20 21 . "github.com/smartystreets/goconvey/convey" 22 "google.golang.org/protobuf/proto" 23 24 "go.chromium.org/luci/scheduler/appengine/catalog" 25 "go.chromium.org/luci/scheduler/appengine/engine" 26 "go.chromium.org/luci/scheduler/appengine/messages" 27 "go.chromium.org/luci/scheduler/appengine/task" 28 "go.chromium.org/luci/scheduler/appengine/task/urlfetch" 29 ) 30 31 func TestGetJobTraits(t *testing.T) { 32 t.Parallel() 33 Convey("works", t, func() { 34 cat := catalog.New() 35 So(cat.RegisterTaskManager(&urlfetch.TaskManager{}), ShouldBeNil) 36 ctx := context.Background() 37 38 Convey("bad task", func() { 39 taskBlob, err := proto.Marshal(&messages.TaskDefWrapper{ 40 Noop: &messages.NoopTask{}, 41 }) 42 So(err, ShouldBeNil) 43 traits, err := GetJobTraits(ctx, cat, &engine.Job{ 44 Task: taskBlob, 45 }) 46 So(err, ShouldNotBeNil) 47 So(traits, ShouldResemble, task.Traits{}) 48 }) 49 50 Convey("OK task", func() { 51 taskBlob, err := proto.Marshal(&messages.TaskDefWrapper{ 52 UrlFetch: &messages.UrlFetchTask{Url: "http://example.com/path"}, 53 }) 54 So(err, ShouldBeNil) 55 traits, err := GetJobTraits(ctx, cat, &engine.Job{ 56 Task: taskBlob, 57 }) 58 So(err, ShouldBeNil) 59 So(traits, ShouldResemble, task.Traits{}) 60 }) 61 }) 62 }