github.com/google/cadvisor@v0.49.1/perf/manager_libpfm_test.go (about)

     1  //go:build libpfm && cgo
     2  // +build libpfm,cgo
     3  
     4  // Copyright 2020 Google Inc. All Rights Reserved.
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  
    18  // Manager of perf events for containers.
    19  package perf
    20  
    21  import (
    22  	"testing"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  
    26  	info "github.com/google/cadvisor/info/v1"
    27  	"github.com/google/cadvisor/stats"
    28  )
    29  
    30  func TestEmptyConfigPassed(t *testing.T) {
    31  	manager, err := NewManager("testing/perf-no-events.json", []info.Node{})
    32  
    33  	assert.NotNil(t, err)
    34  	assert.Nil(t, manager)
    35  }
    36  
    37  func TestNoConfigFilePassed(t *testing.T) {
    38  	manager, err := NewManager("", []info.Node{})
    39  
    40  	assert.Nil(t, err)
    41  	_, ok := manager.(*stats.NoopManager)
    42  	assert.True(t, ok)
    43  }
    44  
    45  func TestNonExistentFile(t *testing.T) {
    46  	manager, err := NewManager("this-file-is-so-non-existent", []info.Node{})
    47  
    48  	assert.NotNil(t, err)
    49  	assert.Nil(t, manager)
    50  }
    51  
    52  func TestMalformedJsonFile(t *testing.T) {
    53  	manager, err := NewManager("testing/this-is-some-random.json", []info.Node{})
    54  
    55  	assert.NotNil(t, err)
    56  	assert.Nil(t, manager)
    57  }
    58  
    59  func TestNewManager(t *testing.T) {
    60  	managerInstance, err := NewManager("testing/perf.json", []info.Node{})
    61  
    62  	assert.Nil(t, err)
    63  	_, ok := managerInstance.(*manager)
    64  	assert.True(t, ok)
    65  }