|
| 1 | +// Copyright 2016 CoreOS, Inc. |
| 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 util |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | +) |
| 20 | + |
| 21 | +func testIsRunningSystemd(t *testing.T) { |
| 22 | + if !IsRunningSystemd() { |
| 23 | + t.Skip("Not running on a systemd host") |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func TestRunningFromSystemService(t *testing.T) { |
| 28 | + testIsRunningSystemd(t) |
| 29 | + t.Parallel() |
| 30 | + |
| 31 | + // tests shouldn't be running as a service |
| 32 | + s, err := RunningFromSystemService() |
| 33 | + if err != nil { |
| 34 | + t.Error(err.Error()) |
| 35 | + } else if s { |
| 36 | + t.Errorf("tests aren't expected to run as a service") |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +func TestCurrentUnitName(t *testing.T) { |
| 41 | + testIsRunningSystemd(t) |
| 42 | + |
| 43 | + s, err := CurrentUnitName() |
| 44 | + if err != nil { |
| 45 | + t.Error(err.Error()) |
| 46 | + } |
| 47 | + if s == "" { |
| 48 | + t.Error("CurrentUnitName returned a empty string") |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func TestGetMachineID(t *testing.T) { |
| 53 | + testIsRunningSystemd(t) |
| 54 | + |
| 55 | + id, err := GetMachineID() |
| 56 | + if err != nil { |
| 57 | + t.Error(err.Error()) |
| 58 | + } |
| 59 | + if id == "" { |
| 60 | + t.Error("GetMachineID returned a empty string") |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +func TestGetRunningSlice(t *testing.T) { |
| 65 | + testIsRunningSystemd(t) |
| 66 | + |
| 67 | + s, err := getRunningSlice() |
| 68 | + if err != nil { |
| 69 | + t.Error(err.Error()) |
| 70 | + } |
| 71 | + if s == "" { |
| 72 | + t.Error("getRunningSlice returned a empty string") |
| 73 | + } |
| 74 | +} |
0 commit comments