github.com/google/cadvisor@v0.49.1/integration/tests/api/machine_test.go (about)

     1  // Copyright 2014 Google Inc. All Rights Reserved.
     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 api
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/google/cadvisor/integration/framework"
    21  )
    22  
    23  func TestMachineInformationIsReturned(t *testing.T) {
    24  	fm := framework.New(t)
    25  	defer fm.Cleanup()
    26  
    27  	machineInfo, err := fm.Cadvisor().Client().MachineInfo()
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  
    32  	// Check for "sane" values. Note these can change with time.
    33  	if machineInfo.NumCores <= 0 || machineInfo.NumCores >= 1000000 {
    34  		t.Errorf("Machine info has unexpected number of cores: %v", machineInfo.NumCores)
    35  	}
    36  	if machineInfo.MemoryCapacity == 0 || machineInfo.MemoryCapacity >= (1<<50 /* 1PB */) {
    37  		t.Errorf("Machine info has unexpected amount of memory: %v", machineInfo.MemoryCapacity)
    38  	}
    39  	if len(machineInfo.Filesystems) == 0 {
    40  		t.Errorf("Expected to have some filesystems, found none")
    41  	}
    42  	for _, fs := range machineInfo.Filesystems {
    43  		if fs.Device == "" {
    44  			t.Errorf("Expected a non-empty device name in: %+v", fs)
    45  		}
    46  		if fs.Capacity >= (1 << 60 /* 1 EB*/) {
    47  			t.Errorf("Unexpected capacity in device %q: %v", fs.Device, fs.Capacity)
    48  		}
    49  		if fs.Type == "" {
    50  			t.Errorf("Filesystem type is not set")
    51  		} else if fs.Type == "vfs" && fs.Inodes == 0 {
    52  			if fs.Device != "devpts" {
    53  				t.Errorf("Inodes not available for device %q", fs.Device)
    54  			}
    55  		}
    56  	}
    57  }