From faa84da28ce110c5c112cd4db2a9552d1618e060 Mon Sep 17 00:00:00 2001 From: James Fantin-Hardesty <24646452+jfantinhardesty@users.noreply.github.com> Date: Fri, 22 Sep 2023 08:55:03 -0600 Subject: [PATCH] test: Add unit test GitHub Action (#3) * Add unit tests on GitHub actions * Fix lint errors and workload * Make prefix path unique so multiple test runners don't collide * Update when action runs * Fix spelling errors --- .gitattributes | 2 + .github/workflows/unit-test.yml | 206 ++++++++++++++++++ .golangci.yml | 3 +- cmd/service_windows.go | 10 +- common/log/sys_logger_windows.go | 14 +- component/azstorage/block_blob.go | 16 +- component/azstorage/config.go | 2 +- component/azstorage/connection.go | 4 +- component/azstorage/datalake.go | 8 +- component/block_cache/block_cache_linux.go | 4 +- component/s3storage/client.go | 12 +- component/s3storage/connection.go | 4 +- component/s3storage/s3storage_test.go | 2 +- component/s3storage/s3wrappers.go | 2 +- component/s3storage/utils.go | 2 +- component/stream/read_write_filename.go | 6 +- internal/winservice/service_windows.go | 4 +- .../cloudfuse_stats/stats_reader_windows.go | 2 +- 18 files changed, 256 insertions(+), 47 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/workflows/unit-test.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..09bc62c13 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto \ No newline at end of file diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 000000000..55301a49f --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,206 @@ +name: Unit-Tests +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + inputs: + manual: + description: 'Manual Run' + type: boolean + required: true + default: true + +jobs: + test: + strategy: + matrix: + go: ['1.20'] + job_name: ['linux', 'windows'] + + include: + - job_name: linux + os: ubuntu-latest + containerName: 'test-cnt-ubn' + + - job_name: windows + os: windows-latest + containerName: 'test-cnt-win' + cgo: '0' + + name: Build and Test on + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go }} + check-latest: true + - run: go version + + - name: Set CGO + shell: bash + run: | + if [[ "${{ matrix.cgo }}" != "" ]]; then echo 'CGO_ENABLED=${{ matrix.cgo }}' >> $GITHUB_ENV ; fi + + - name: Install libfuse on Linux + shell: bash + run: | + sudo apt-get install fuse3 libfuse-dev rpm pkg-config + if: matrix.os == 'ubuntu-latest' + + - name: Go module cache + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Build + run: | + ./build.sh + + - name: Create Azure Configuration File on Linux + run: |- + cnfFile=$HOME/azuretest.json + echo $cnfFile + touch $cnfFile + echo "{" > $cnfFile + echo "\"block-acct\"": "\"${{ secrets.AZTEST_BLOCK_ACC_NAME }}\"", >> $cnfFile + echo "\"adls-acct\"": "\"${{ secrets.AZTEST_ADLS_ACC_NAME }}\"", >> $cnfFile + echo "\"block-cont\"": "\"${{ matrix.containerName }}\"", >> $cnfFile + echo "\"adls-cont\"": "\"${{ matrix.containerName }}\"", >> $cnfFile + echo "\"block-key\"": "\"${{ secrets.AZTEST_BLOCK_KEY }}\"", >> $cnfFile + echo "\"adls-key\"": "\"${{ secrets.AZTEST_ADLS_KEY }}\"", >> $cnfFile + echo "\"block-sas\"": "\"${{ secrets.AZTEST_BLOCK_SAS }}\"", >> $cnfFile + echo "\"block-cont-sas-ubn-18\"": "\"${{ secrets.AZTEST_BLOCK_CONT_SAS_UBN_18 }}\"", >> $cnfFile + echo "\"block-cont-sas-ubn-20\"": "\"${{ secrets.AZTEST_BLOCK_CONT_SAS_UBN_20 }}\"", >> $cnfFile + echo "\"adls-sas\"": "\"${{ secrets.AZTEST_ADLS_SAS }}\"", >> $cnfFile + echo "\"msi-appid\"": "\"${{ secrets.AZTEST_APP_ID }}\"", >> $cnfFile + echo "\"msi-resid\"": "\"${{ secrets.AZTEST_RES_ID }}\"", >> $cnfFile + echo "\"msi-objid\"": "\"${{ secrets.AZTEST_OBJ_ID }}\"", >> $cnfFile + echo "\"spn-client\"": "\"${{ secrets.AZTEST_CLIENT }}\"", >> $cnfFile + echo "\"spn-tenant\"": "\"${{ secrets.AZTEST_TENANT }}\"", >> $cnfFile + echo "\"spn-secret\"": "\"${{ secrets.AZTEST_SECRET }}\"", >> $cnfFile + echo "\"skip-msi\"": "true", >> $cnfFile + echo "\"proxy-address\"": "\"\"" >> $cnfFile + echo "}" >> $cnfFile + if: matrix.os == 'ubuntu-latest' + + - name: Create Azure Configuration File on Windows + run: |- + $cnfFile="~\azuretest.json" + Write-Host $cnfFile + $content = @" + { + "block-acct": "${{ secrets.AZTEST_BLOCK_ACC_NAME }}", + "adls-acct": "${{ secrets.AZTEST_ADLS_ACC_NAME }}", + "block-cont": "${{ matrix.containerName }}", + "adls-cont": "${{ matrix.containerName }}", + "block-key": "${{ secrets.AZTEST_BLOCK_KEY }}", + "adls-key": "${{ secrets.AZTEST_ADLS_KEY }}", + "block-sas": "${{ secrets.AZTEST_BLOCK_SAS }}", + "block-cont-sas-ubn-18": "${{ secrets.AZTEST_BLOCK_CONT_SAS_UBN_18 }}", + "block-cont-sas-ubn-20": "${{ secrets.AZTEST_BLOCK_CONT_SAS_UBN_20 }}", + "adls-sas": "${{ secrets.AZTEST_ADLS_SAS }}", + "msi-appid": "${{ secrets.AZTEST_APP_ID }}", + "msi-resid": "${{ secrets.AZTEST_RES_ID }}", + "msi-objid": "${{ secrets.AZTEST_OBJ_ID }}", + "spn-client": "${{ secrets.AZTEST_CLIENT }}", + "spn-tenant": "${{ secrets.AZTEST_TENANT }}", + "spn-secret": "${{ secrets.AZTEST_SECRET }}", + "skip-msi": true, + "proxy-address": "" + } + "@ + $content | Out-File -FilePath $cnfFile -Encoding Ascii + shell: powershell + if: matrix.os == 'windows-latest' + + - name: Create S3 Configuration File on Linux + run: |- + cnfFile=$HOME/s3test.json + echo $cnfFile + touch $cnfFile + echo "{" > $cnfFile + echo "\"bucket-name\"": "\"${{ secrets.S3TEST_BUCKET_NAME }}\"", >> $cnfFile + echo "\"access-key\"": "\"${{ secrets.S3TEST_ACCESS_KEY }}\"", >> $cnfFile + echo "\"secret-key\"": "\"${{ secrets.S3TEST_SECRET_KEY }}\"", >> $cnfFile + echo "\"endpoint\"": "\"${{ secrets.S3TEST_ENDPOINT }}\"", >> $cnfFile + echo "\"region\"": "\"${{ secrets.S3TEST_REGION }}\"" >> $cnfFile + echo "}" >> $cnfFile + if: matrix.os == 'ubuntu-latest' + + - name: Create S3 Configuration File on Windows + run: |- + $cnfFile="~\s3test.json" + Write-Host $cnfFile + $content = @" + { + "bucket-name": "${{ secrets.S3TEST_BUCKET_NAME }}", + "access-key": "${{ secrets.S3TEST_ACCESS_KEY }}", + "secret-key": "${{ secrets.S3TEST_SECRET_KEY }}", + "endpoint": "${{ secrets.S3TEST_ENDPOINT }}", + "region": "${{ secrets.S3TEST_REGION }}" + } + "@ + $content | Out-File -FilePath $cnfFile -Encoding Ascii + shell: powershell + if: matrix.os == 'windows-latest' + + - name: Run unit tests + run: go test -v -timeout=2h ./... --tags=unittest + + lint: + name: Lint + runs-on: ubuntu-latest + env: + go: '1.20' + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.go }} + check-latest: true + - run: go version + + - name: Set CGO + shell: bash + run: | + if [[ "${{ env.go }}" != "" ]]; then echo 'CGO_ENABLED=${{ env.go }}' >> $GITHUB_ENV ; fi + + - name: Install libfuse on Linux + shell: bash + run: | + sudo apt-get install libfuse-dev + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Require: The version of golangci-lint to use. + # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. + # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. + version: latest + + # Optional: golangci-lint command line arguments. + args: --tests=false --timeout=5m --skip-dirs test,common/stats_collector,common/stats_monitor --skip-files component/libfuse/libfuse2_handler_test_wrapper.go --out-format=github-actions + + - name: Notice file check + run: | + ./notices_fix.sh + result=$(git diff NOTICE | wc -l) + if [ $result -ne 0 ]; then + echo "Notices needs a fix. Run ./notices_fix.sh and commit NOTICE file." + exit 1 + else + echo "Notices are up to date." + fi diff --git a/.golangci.yml b/.golangci.yml index b5d5b1253..eafd6bbb3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,7 +9,8 @@ linters: - gosimple # Linter for Go source code that specializes in simplifying code - govet # Vet examines Go source code and reports suspicious constructs - ineffassign # Detects when assignments to existing variables are not used - - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. + - misspell # Finds commonly misspelled English words in comments. + - predeclared # Find code that shadows one of Go's predeclared identifiers. - staticcheck # Set of rules from staticcheck. - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code - unused # Checks Go code for unused constants, variables, functions and types diff --git a/cmd/service_windows.go b/cmd/service_windows.go index 76ed6aac1..897959bed 100644 --- a/cmd/service_windows.go +++ b/cmd/service_windows.go @@ -253,7 +253,7 @@ func installService() error { if err != nil { return err } - defer scm.Disconnect() + defer scm.Disconnect() //nolint // Don't install the service if it already exists service, err := scm.OpenService(SvcName) @@ -283,7 +283,7 @@ func removeService() error { if err != nil { return err } - defer scm.Disconnect() + defer scm.Disconnect() //nolint service, err := scm.OpenService(SvcName) if err != nil { @@ -312,7 +312,7 @@ func startService() error { if err != nil { return err } - defer scm.Disconnect() + defer scm.Disconnect() //nolint service, err := scm.OpenService(SvcName) if err != nil { @@ -333,7 +333,7 @@ func stopService() error { if err != nil { return err } - defer scm.Disconnect() + defer scm.Disconnect() //nolint service, err := scm.OpenService(SvcName) if err != nil { @@ -370,7 +370,7 @@ func isServiceRunning() (bool, error) { if err != nil { return false, err } - defer scm.Disconnect() + defer scm.Disconnect() //nolint service, err := scm.OpenService(SvcName) if err != nil { diff --git a/common/log/sys_logger_windows.go b/common/log/sys_logger_windows.go index 357fdedfc..aa2030bbf 100644 --- a/common/log/sys_logger_windows.go +++ b/common/log/sys_logger_windows.go @@ -73,7 +73,7 @@ func (sl *SysLogger) GetLoggerObj() *log.Logger { func (sl *SysLogger) SetLogLevel(level common.LogLevel) { sl.level = level - sl.logEvent(common.ELogLevel.LOG_CRIT(), "Log level reset to :"+level.String()) + _ = sl.logEvent(common.ELogLevel.LOG_CRIT(), "Log level reset to :"+level.String()) } func (sl *SysLogger) GetType() string { @@ -125,42 +125,42 @@ func (sl *SysLogger) logEvent(lvl common.LogLevel, msg string) error { func (sl *SysLogger) Debug(format string, args ...interface{}) { if sl.level >= common.ELogLevel.LOG_DEBUG() { msg := fmt.Sprintf(format, args...) - sl.logEvent(common.ELogLevel.LOG_DEBUG(), msg) + _ = sl.logEvent(common.ELogLevel.LOG_DEBUG(), msg) } } func (sl *SysLogger) Trace(format string, args ...interface{}) { if sl.level >= common.ELogLevel.LOG_TRACE() { msg := fmt.Sprintf(format, args...) - sl.logEvent(common.ELogLevel.LOG_TRACE(), msg) + _ = sl.logEvent(common.ELogLevel.LOG_TRACE(), msg) } } func (sl *SysLogger) Info(format string, args ...interface{}) { if sl.level >= common.ELogLevel.LOG_INFO() { msg := fmt.Sprintf(format, args...) - sl.logEvent(common.ELogLevel.LOG_INFO(), msg) + _ = sl.logEvent(common.ELogLevel.LOG_INFO(), msg) } } func (sl *SysLogger) Warn(format string, args ...interface{}) { if sl.level >= common.ELogLevel.LOG_WARNING() { msg := fmt.Sprintf(format, args...) - sl.logEvent(common.ELogLevel.LOG_WARNING(), msg) + _ = sl.logEvent(common.ELogLevel.LOG_WARNING(), msg) } } func (sl *SysLogger) Err(format string, args ...interface{}) { if sl.level >= common.ELogLevel.LOG_ERR() { msg := fmt.Sprintf(format, args...) - sl.logEvent(common.ELogLevel.LOG_ERR(), msg) + _ = sl.logEvent(common.ELogLevel.LOG_ERR(), msg) } } func (sl *SysLogger) Crit(format string, args ...interface{}) { if sl.level >= common.ELogLevel.LOG_CRIT() { msg := fmt.Sprintf(format, args...) - sl.logEvent(common.ELogLevel.LOG_CRIT(), msg) + _ = sl.logEvent(common.ELogLevel.LOG_CRIT(), msg) } } diff --git a/component/azstorage/block_blob.go b/component/azstorage/block_blob.go index 098a8ca73..023162f36 100644 --- a/component/azstorage/block_blob.go +++ b/component/azstorage/block_blob.go @@ -738,22 +738,22 @@ func (bb *BlockBlob) ReadToFile(name string, offset int64, count int64, fi *os.F } // ReadBuffer : Download a specific range from a blob to a buffer -func (bb *BlockBlob) ReadBuffer(name string, offset int64, len int64) ([]byte, error) { +func (bb *BlockBlob) ReadBuffer(name string, offset int64, length int64) ([]byte, error) { log.Trace("BlockBlob::ReadBuffer : name %s", name) var buff []byte - if len == 0 { - len = azblob.CountToEnd + if length == 0 { + length = azblob.CountToEnd attr, err := bb.GetAttr(name) if err != nil { return buff, err } buff = make([]byte, attr.Size) } else { - buff = make([]byte, len) + buff = make([]byte, length) } blobURL := bb.getBlobURL(name) - err := azblob.DownloadBlobToBuffer(context.Background(), blobURL, offset, len, buff, bb.downloadOptions) + err := azblob.DownloadBlobToBuffer(context.Background(), blobURL, offset, length, buff, bb.downloadOptions) if err != nil { e := storeBlobErrToErr(err) @@ -771,12 +771,12 @@ func (bb *BlockBlob) ReadBuffer(name string, offset int64, len int64) ([]byte, e } // ReadInBuffer : Download specific range from a file to a user provided buffer -func (bb *BlockBlob) ReadInBuffer(name string, offset int64, len int64, data []byte) error { +func (bb *BlockBlob) ReadInBuffer(name string, offset int64, length int64, data []byte) error { // log.Trace("BlockBlob::ReadInBuffer : name %s", name) blobURL := bb.getBlobURL(name) opt := bb.downloadOptions - opt.BlockSize = len - err := azblob.DownloadBlobToBuffer(context.Background(), blobURL, offset, len, data, opt) + opt.BlockSize = length + err := azblob.DownloadBlobToBuffer(context.Background(), blobURL, offset, length, data, opt) if err != nil { e := storeBlobErrToErr(err) diff --git a/component/azstorage/config.go b/component/azstorage/config.go index 15005a42d..7df53babd 100644 --- a/component/azstorage/config.go +++ b/component/azstorage/config.go @@ -487,7 +487,7 @@ func ParseAndValidateConfig(az *AzStorage, opt AzStorageOptions) error { } log.Info("ParseAndValidateConfig : Account: %s, Container: %s, AccountType: %s, Auth: %s, Prefix: %s, Endpoint: %s, ListBlock: %d, MD5 : %v %v, "+ - "Virtual Directory: %v, Max Results For List %v, Disable Compression: %v, Restircted Windows Characters: %v", + "Virtual Directory: %v, Max Results For List %v, Disable Compression: %v, Restricted Windows Characters: %v", az.stConfig.authConfig.AccountName, az.stConfig.container, az.stConfig.authConfig.AccountType, az.stConfig.authConfig.AuthMode, az.stConfig.prefixPath, az.stConfig.authConfig.Endpoint, az.stConfig.cancelListForSeconds, az.stConfig.validateMD5, az.stConfig.updateMD5, az.stConfig.virtualDirectory, az.stConfig.maxResultsForList, az.stConfig.disableCompression, az.stConfig.restrictedCharsWin) diff --git a/component/azstorage/connection.go b/component/azstorage/connection.go index 851045cd9..6f28b58f1 100644 --- a/component/azstorage/connection.go +++ b/component/azstorage/connection.go @@ -119,8 +119,8 @@ type AzConnection interface { List(prefix string, marker *string, count int32) ([]*internal.ObjAttr, *string, error) ReadToFile(name string, offset int64, count int64, fi *os.File) error - ReadBuffer(name string, offset int64, len int64) ([]byte, error) - ReadInBuffer(name string, offset int64, len int64, data []byte) error + ReadBuffer(name string, offset int64, length int64) ([]byte, error) + ReadInBuffer(name string, offset int64, length int64, data []byte) error WriteFromFile(name string, metadata map[string]string, fi *os.File) error WriteFromBuffer(name string, metadata map[string]string, data []byte) error diff --git a/component/azstorage/datalake.go b/component/azstorage/datalake.go index 7f94b3555..16da71300 100644 --- a/component/azstorage/datalake.go +++ b/component/azstorage/datalake.go @@ -559,13 +559,13 @@ func (dl *Datalake) ReadToFile(name string, offset int64, count int64, fi *os.Fi } // ReadBuffer : Download a specific range from a file to a buffer -func (dl *Datalake) ReadBuffer(name string, offset int64, len int64) ([]byte, error) { - return dl.BlockBlob.ReadBuffer(name, offset, len) +func (dl *Datalake) ReadBuffer(name string, offset int64, length int64) ([]byte, error) { + return dl.BlockBlob.ReadBuffer(name, offset, length) } // ReadInBuffer : Download specific range from a file to a user provided buffer -func (dl *Datalake) ReadInBuffer(name string, offset int64, len int64, data []byte) error { - return dl.BlockBlob.ReadInBuffer(name, offset, len, data) +func (dl *Datalake) ReadInBuffer(name string, offset int64, length int64, data []byte) error { + return dl.BlockBlob.ReadInBuffer(name, offset, length, data) } // WriteFromFile : Upload local file to file diff --git a/component/block_cache/block_cache_linux.go b/component/block_cache/block_cache_linux.go index 939bf595a..6abf193d6 100644 --- a/component/block_cache/block_cache_linux.go +++ b/component/block_cache/block_cache_linux.go @@ -391,7 +391,7 @@ func (bc *BlockCache) ReadInBuffer(options internal.ReadInBufferOptions) (int, e return dataRead, nil } -// getBlock: From offset generate the Block index and get the Block corrosponding to it +// getBlock: From offset generate the Block index and get the Block corresponding to it /* Base logic of getBlock: Check if the given block is already available or not if not @@ -446,7 +446,7 @@ func (bc *BlockCache) getBlock(handle *handlemap.Handle, readoffset uint64) (*Bl node, found = handle.GetValue(fmt.Sprintf("%v", index)) if !found { log.Err("BlockCache::getBlock : Failed to get the required block %v=>%s (offset %v, index %v)", handle.ID, handle.Path, readoffset, index) - return nil, fmt.Errorf("not able to find block immediately after scheudling") + return nil, fmt.Errorf("not able to find block immediately after scheduling") } } diff --git a/component/s3storage/client.go b/component/s3storage/client.go index 109e724c9..3c66f6a5a 100644 --- a/component/s3storage/client.go +++ b/component/s3storage/client.go @@ -453,10 +453,10 @@ func (cl *Client) ReadToFile(name string, offset int64, count int64, fi *os.File // Reads starting at a byte offset from the start of the object, with length in bytes = len. // len = 0 reads to the end of the object. // name is the file path -func (cl *Client) ReadBuffer(name string, offset int64, len int64, isSymlink bool) ([]byte, error) { - log.Trace("Client::ReadBuffer : name %s (%d+%d)", name, offset, len) +func (cl *Client) ReadBuffer(name string, offset int64, length int64, isSymlink bool) ([]byte, error) { + log.Trace("Client::ReadBuffer : name %s (%d+%d)", name, offset, length) // get object data - objectDataReader, err := cl.getObject(name, offset, len, isSymlink) + objectDataReader, err := cl.getObject(name, offset, length, isSymlink) if err != nil { log.Err("Client::ReadBuffer : getObject(%s) failed. Here's why: %v", name, err) return nil, err @@ -476,10 +476,10 @@ func (cl *Client) ReadBuffer(name string, offset int64, len int64, isSymlink boo // Reads starting at a byte offset from the start of the object, with length in bytes = len. // len = 0 reads to the end of the object. // name is the file path. -func (cl *Client) ReadInBuffer(name string, offset int64, len int64, data []byte) error { - log.Trace("Client::ReadInBuffer : name %s offset %d len %d", name, offset, len) +func (cl *Client) ReadInBuffer(name string, offset int64, length int64, data []byte) error { + log.Trace("Client::ReadInBuffer : name %s offset %d len %d", name, offset, length) // get object data - objectDataReader, err := cl.getObject(name, offset, len, false) + objectDataReader, err := cl.getObject(name, offset, length, false) if err != nil { log.Err("Client::ReadInBuffer : getObject(%s) failed. Here's why: %v", name, err) return err diff --git a/component/s3storage/connection.go b/component/s3storage/connection.go index ccde37585..43ebcdd5d 100644 --- a/component/s3storage/connection.go +++ b/component/s3storage/connection.go @@ -107,8 +107,8 @@ type S3Connection interface { List(prefix string, marker *string, count int32) ([]*internal.ObjAttr, *string, error) ReadToFile(name string, offset int64, count int64, fi *os.File) error - ReadBuffer(name string, offset int64, len int64, isSymlink bool) ([]byte, error) - ReadInBuffer(name string, offset int64, len int64, data []byte) error + ReadBuffer(name string, offset int64, length int64, isSymlink bool) ([]byte, error) + ReadInBuffer(name string, offset int64, length int64, data []byte) error WriteFromFile(name string, metadata map[string]string, fi *os.File) error WriteFromBuffer(name string, metadata map[string]string, data []byte) error diff --git a/component/s3storage/s3storage_test.go b/component/s3storage/s3storage_test.go index d8cbc3ef4..ecbfe29cf 100644 --- a/component/s3storage/s3storage_test.go +++ b/component/s3storage/s3storage_test.go @@ -323,7 +323,7 @@ func (s *s3StorageTestSuite) setupTestHelper(configuration string, bucket string // TODO: once we have a separate test bucket, or (preferably) the ability to create one in testing // remove this prefix so we can test operations at the root of the bucket if s.s3Storage.stConfig.prefixPath == "" { - s.s3Storage.stConfig.prefixPath = "test" + s.s3Storage.stConfig.prefixPath = "test" + randomString(8) err = s.s3Storage.storage.SetPrefixPath(s.s3Storage.stConfig.prefixPath) if err != nil { fmt.Printf("s3StorageTestSuite::setupTestHelper : SetPrefixPath failed. Here's why: %v\n", err) diff --git a/component/s3storage/s3wrappers.go b/component/s3storage/s3wrappers.go index 0d52ba4ce..33df41467 100644 --- a/component/s3storage/s3wrappers.go +++ b/component/s3storage/s3wrappers.go @@ -457,7 +457,7 @@ func createObjAttr(path string, size int64, lastModified time.Time, isSymLink bo } // create an object attributes struct for a directory -func createObjAttrDir(path string) (attr *internal.ObjAttr) { +func createObjAttrDir(path string) (attr *internal.ObjAttr) { //nolint // strip any trailing slash path = internal.TruncateDirName(path) // For these dirs we get only the name and no other properties so hardcoding time to current time diff --git a/component/s3storage/utils.go b/component/s3storage/utils.go index 9dca4e1d5..99019e318 100644 --- a/component/s3storage/utils.go +++ b/component/s3storage/utils.go @@ -212,7 +212,7 @@ func getContentType(key string) string { return "application/octet-stream" } -func populateContentType(newSet string) error { +func populateContentType(newSet string) error { //nolint var data map[string]string if err := json.Unmarshal([]byte(newSet), &data); err != nil { log.Err("Failed to parse config file : %s [%s]", newSet, err.Error()) diff --git a/component/stream/read_write_filename.go b/component/stream/read_write_filename.go index aaa8dec82..292c2727e 100644 --- a/component/stream/read_write_filename.go +++ b/component/stream/read_write_filename.go @@ -288,19 +288,19 @@ func (rw *ReadWriteFilenameCache) GetAttr(options internal.GetAttrOptions) (*int return attrs, nil } -func (rw *ReadWriteFilenameCache) purge(fileName string, close bool) { +func (rw *ReadWriteFilenameCache) purge(fileName string, closeOp bool) { // check if this file is cached rw.Lock() defer rw.Unlock() buffer, found := rw.fileCache[fileName] if found { // if it is a close operation then decrement the handle count on the buffer - if close { + if closeOp { atomic.AddInt64(&buffer.HandleCount, -1) } // rw.RUnlock() // if the handle count is 0 (no open handles) purge the buffer - if atomic.LoadInt64(&buffer.HandleCount) <= 0 || !close { + if atomic.LoadInt64(&buffer.HandleCount) <= 0 || !closeOp { delete(rw.fileCache, fileName) buffer.Lock() defer buffer.Unlock() diff --git a/internal/winservice/service_windows.go b/internal/winservice/service_windows.go index 76aaa2a4e..f43f3bbd0 100644 --- a/internal/winservice/service_windows.go +++ b/internal/winservice/service_windows.go @@ -77,7 +77,7 @@ func (m *Cloudfuse) Execute(_ []string, r <-chan svc.ChangeRequest, changes chan changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} log.Trace("Successfully started %s service", SvcName) - for { + for { //nolint select { case c := <-r: switch c.Cmd { @@ -232,7 +232,7 @@ func winFspCommand(command []byte) ([]string, error) { if err != nil { return retStrings, err } - defer windows.CloseHandle(handle) + defer windows.CloseHandle(handle) //nolint // Send the command to WinFSP var overlapped windows.Overlapped diff --git a/tools/health-monitor/monitor/cloudfuse_stats/stats_reader_windows.go b/tools/health-monitor/monitor/cloudfuse_stats/stats_reader_windows.go index 92d2dddc1..d9c4e88ea 100644 --- a/tools/health-monitor/monitor/cloudfuse_stats/stats_reader_windows.go +++ b/tools/health-monitor/monitor/cloudfuse_stats/stats_reader_windows.go @@ -83,7 +83,7 @@ func (cfs *CloudfuseStats) statsReader() error { } log.Info("StatsReader::statsReader : Connected transfer pipe %s", cfs.transferPipe) - go cfs.handleStatsReader(handle) + go cfs.handleStatsReader(handle) //nolint } }