Skip to content

Commit

Permalink
test: Add unit test GitHub Action (#3)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jfantinhardesty authored Sep 22, 2023
1 parent a5cce79 commit faa84da
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
206 changes: 206 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions cmd/service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions common/log/sys_logger_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand Down
16 changes: 8 additions & 8 deletions component/azstorage/block_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion component/azstorage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions component/azstorage/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit faa84da

Please sign in to comment.