...

Source file src/github.com/redhat-developer/odo/pkg/util/httpcache_test.go

Documentation: github.com/redhat-developer/odo/pkg/util

     1  package util
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/devfile/library/v2/pkg/testingutil/filesystem"
     9  	dfutil "github.com/devfile/library/v2/pkg/util"
    10  )
    11  
    12  func TestCleanDefaultHTTPCacheDir(t *testing.T) {
    13  	fakeFs := filesystem.NewFakeFs()
    14  	filesToGenerate := 10
    15  	for i := 0; i < filesToGenerate; i++ {
    16  		err := fakeFs.WriteFile(filepath.Join(httpCacheDir, dfutil.GenerateRandomString(10)), []byte(dfutil.GenerateRandomString(10)), os.ModePerm)
    17  		if err != nil {
    18  			t.Error(err)
    19  		}
    20  	}
    21  	files, err := fakeFs.ReadDir(httpCacheDir)
    22  	if err != nil {
    23  		t.Error(err)
    24  	}
    25  	// checking the file count before the run
    26  	if len(files) != filesToGenerate {
    27  		t.Error("the file count in the httpCacheDir don't match files generated")
    28  	}
    29  	err = cleanDefaultHTTPCacheDir(fakeFs)
    30  	if err != nil {
    31  		t.Error(err)
    32  	}
    33  
    34  	newFiles, err := fakeFs.ReadDir(httpCacheDir)
    35  	if err != nil {
    36  		t.Error(err)
    37  	}
    38  
    39  	if len(newFiles) != 0 {
    40  		t.Error("httpCacheDir is not empty after cleanup")
    41  	}
    42  
    43  }
    44  

View as plain text