...

Source file src/github.com/coreos/go-systemd/v22/util/util_test.go

Documentation: github.com/coreos/go-systemd/v22/util

     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  	fromService, err := RunningFromSystemService()
    44  	if err != nil || !fromService {
    45  		t.Skip("Not running from a systemd service")
    46  	}
    47  
    48  	s, err := CurrentUnitName()
    49  	if err != nil {
    50  		t.Error(err.Error())
    51  	}
    52  	if s == "" {
    53  		t.Error("CurrentUnitName returned a empty string")
    54  	}
    55  }
    56  
    57  func TestGetMachineID(t *testing.T) {
    58  	testIsRunningSystemd(t)
    59  
    60  	id, err := GetMachineID()
    61  	if err != nil {
    62  		t.Error(err.Error())
    63  	}
    64  	if id == "" {
    65  		t.Error("GetMachineID returned a empty string")
    66  	}
    67  }
    68  
    69  func TestGetRunningSlice(t *testing.T) {
    70  	testIsRunningSystemd(t)
    71  
    72  	s, err := getRunningSlice()
    73  	if err != nil {
    74  		t.Error(err.Error())
    75  	}
    76  	if s == "" {
    77  		t.Error("getRunningSlice returned a empty string")
    78  	}
    79  }
    80  

View as plain text