Skip to content

Commit

Permalink
Some linting errors (#2532)
Browse files Browse the repository at this point in the history
* Fixing number of linting errors

Signed-off-by: Maciej "Iwan" Iwanowski <maciej.iwanowski@intel.com>
  • Loading branch information
iwankgb committed May 4, 2020
1 parent 3d9cf1c commit a470ec1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
12 changes: 0 additions & 12 deletions .golangci.yml
Expand Up @@ -42,15 +42,3 @@ issues:
# There are more similar issues in this file
- path: utils/cpuload/netlink/netlink.go
text: "Error return value of `binary.Write` is not checked"
# utils/cloudinfo/aws/aws.go:60:28: SA1019: session.New is deprecated: Use NewSession functions to create sessions instead. NewSession has the same functionality as New except an error can be returned when the func is called instead of waiting to receive an error until a request is made. (staticcheck)

This comment has been minimized.

Copy link
@rakeshbhai143

rakeshbhai143 Jun 29, 2023

@###

_****_ sundernohar active

- path: utils/cloudinfo/aws/aws.go
text: "SA1019:"
# manager/manager_test.go:277:29: Error return value of `(*github.com/google/cadvisor/container/testing.MockContainerHandler).GetSpec` is not checked (errcheck)
- path: manager/manager_test.go
text: "Error return value of `.{2}github.com/google/cadvisor/container/testing.MockContainerHandler.{1}.GetSpec` is not checked"
# utils/sysinfo/sysinfo.go:208:7: ineffectual assignment to `err` (ineffassign)
- path: utils/sysinfo/sysinfo.go
text: "ineffectual assignment to `err`|SA4006:"
# cache/memory/memory_test.go:81:23: Error return value of `memoryCache.AddStats` is not checked (errcheck)
- path: cache/memory/memory_test.go
text: "Error return value of `memoryCache.AddStats` is not checked"
12 changes: 6 additions & 6 deletions cache/memory/memory_test.go
Expand Up @@ -67,36 +67,36 @@ func TestAddStats(t *testing.T) {
}

func TestRecentStatsNoRecentStats(t *testing.T) {
memoryCache := makeWithStats(0)
memoryCache := makeWithStats(t, 0)

_, err := memoryCache.RecentStats(containerName, zero, zero, 60)
assert.NotNil(t, err)
}

// Make an instance of InMemoryCache with n stats.
func makeWithStats(n int) *InMemoryCache {
func makeWithStats(t *testing.T, n int) *InMemoryCache {
memoryCache := New(60*time.Second, nil)

for i := 0; i < n; i++ {
memoryCache.AddStats(&cInfo, makeStat(i))
assert.NoError(t, memoryCache.AddStats(&cInfo, makeStat(i)))
}
return memoryCache
}

func TestRecentStatsGetZeroStats(t *testing.T) {
memoryCache := makeWithStats(10)
memoryCache := makeWithStats(t, 10)

assert.Len(t, getRecentStats(t, memoryCache, 0), 0)
}

func TestRecentStatsGetSomeStats(t *testing.T) {
memoryCache := makeWithStats(10)
memoryCache := makeWithStats(t, 10)

assert.Len(t, getRecentStats(t, memoryCache, 5), 5)
}

func TestRecentStatsGetAllStats(t *testing.T) {
memoryCache := makeWithStats(10)
memoryCache := makeWithStats(t, 10)

assert.Len(t, getRecentStats(t, memoryCache, -1), 10)
}
3 changes: 2 additions & 1 deletion manager/manager_test.go
Expand Up @@ -274,7 +274,8 @@ func TestGetContainerInfoV2Failure(t *testing.T) {

// Make GetSpec fail on /c2
mockErr := fmt.Errorf("intentional GetSpec failure")
handlerMap[failing].GetSpec() // Use up default GetSpec call, and replace below
_, err = handlerMap[failing].GetSpec()
assert.NoError(t, err) // Use up default GetSpec call, and replace below
handlerMap[failing].On("GetSpec").Return(info.ContainerSpec{}, mockErr)
handlerMap[failing].On("Exists").Return(true)
m.containers[namespacedContainerName{Name: failing}].infoLastUpdatedTime = time.Time{} // Force GetSpec.
Expand Down
6 changes: 5 additions & 1 deletion utils/cloudinfo/aws/aws.go
Expand Up @@ -57,7 +57,11 @@ func fileContainsAmazonIdentifier(filename string) bool {
}

func getAwsMetadata(name string) string {
client := ec2metadata.New(session.New(&aws.Config{}))
sess, err := session.NewSession(&aws.Config{})
if err != nil {
return info.UnknownInstance
}
client := ec2metadata.New(sess)
data, err := client.GetMetadata(name)
if err != nil {
return info.UnknownInstance
Expand Down
3 changes: 3 additions & 0 deletions utils/sysinfo/sysinfo.go
Expand Up @@ -205,6 +205,9 @@ func GetNodesInfo(sysFs sysfs.SysFs) ([]info.Node, int, error) {

for _, nodeDir := range nodesDirs {
id, err := getMatchedInt(nodeDirRegExp, nodeDir)
if err != nil {
return nil, 0, err
}
node := info.Node{Id: id}

cpuDirs, err := sysFs.GetCPUsPaths(nodeDir)
Expand Down

0 comments on commit a470ec1

Please sign in to comment.