| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package main |
| 6 |
| 7 import ( |
| 8 "testing" |
| 9 |
| 10 "github.com/luci/luci-go/common/environ" |
| 11 "github.com/luci/luci-go/common/logdog/types" |
| 12 |
| 13 . "github.com/luci/luci-go/common/testing/assertions" |
| 14 . "github.com/smartystreets/goconvey/convey" |
| 15 ) |
| 16 |
| 17 func TestCookLogDogPrefix(t *testing.T) { |
| 18 Convey(`With a fake environment`, t, func() { |
| 19 var ( |
| 20 p cookLogDogParams |
| 21 |
| 22 env = environ.New([]string{ |
| 23 "SWARMING_SERVER=server.appspot.com", |
| 24 "SWARMING_TASK_ID=1234567890abcdef", |
| 25 }) |
| 26 ) |
| 27 |
| 28 Convey(`Will prefer command-line prefix`, func() { |
| 29 p.prefix = "foo/bar" |
| 30 |
| 31 pfx, err := p.getPrefix(env) |
| 32 So(err, ShouldBeNil) |
| 33 So(pfx, ShouldEqual, types.StreamName("foo/bar")) |
| 34 }) |
| 35 |
| 36 Convey(`Can generate a LogDog prefix`, func() { |
| 37 pfx, err := p.getPrefix(env) |
| 38 So(err, ShouldBeNil) |
| 39 So(pfx, ShouldEqual, types.StreamName("swarm/server.apps
pot.com/1234567890abcdef")) |
| 40 }) |
| 41 |
| 42 Convey(`If Swarming server is missing from the environment, will
fail.`, func() { |
| 43 env.Set("SWARMING_SERVER", "") |
| 44 |
| 45 _, err := p.getPrefix(env) |
| 46 So(err, ShouldErrLike, "missing or empty SWARMING_SERVER
") |
| 47 }) |
| 48 |
| 49 Convey(`If Swarming task ID is missing from the environment, wil
l fail.`, func() { |
| 50 env.Set("SWARMING_TASK_ID", "") |
| 51 |
| 52 _, err := p.getPrefix(env) |
| 53 So(err, ShouldErrLike, "missing or empty SWARMING_TASK_I
D") |
| 54 }) |
| 55 }) |
| 56 } |
| OLD | NEW |