Skip to content

Commit

Permalink
fix : remove unnecessary logging for crc-exists file (#3676)
Browse files Browse the repository at this point in the history
Remove unnecessary debug log statement for crc-exists file from
filestore Exists() method

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Dec 27, 2024
1 parent 6e99137 commit 7b6b010
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion pkg/libmachine/persist/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (s Filestore) SetExists(name string) error {
func (s Filestore) Exists(name string) (bool, error) {
filename := filepath.Join(s.MachinesDir, name, fmt.Sprintf(".%s-exist", name))
_, err := os.Stat(filename)
log.Debugf("Checking file: %s", filename)

if os.IsNotExist(err) {
return false, nil
Expand Down
24 changes: 24 additions & 0 deletions pkg/libmachine/persist/filestore_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package persist

import (
"bytes"
"encoding/json"
"github.com/sirupsen/logrus"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -106,6 +108,28 @@ func TestStoreLoad(t *testing.T) {
assert.NoError(t, json.Unmarshal(rawDataDriver.Data, &realDriver))
}

func TestStoreExists_WhenExecuted_ThenDoesNotLogFileCheckInDebugMode(t *testing.T) {
// Given
var logBuffer bytes.Buffer
logrus.SetOutput(&logBuffer)
oldDebugLevel := logrus.GetLevel()
logrus.SetLevel(logrus.DebugLevel)
defer logrus.SetOutput(os.Stdout)
defer logrus.SetLevel(oldDebugLevel)
store := getTestStore(t)
h := testHost()

// When
exists, err := store.Exists(h.Name)

// Then
assert.NoError(t, err)
assert.False(t, exists)
logContents := logBuffer.String()
assert.Equal(t, logBuffer.Len(), 0)
assert.NotContains(t, logContents, "Checking file:")
}

func testHost() *host.Host {
return &host.Host{
ConfigVersion: host.Version,
Expand Down

0 comments on commit 7b6b010

Please sign in to comment.