Unit tests for mount, mountv1 and doc commands (#897)

This commit is contained in:
Sourav Gupta 2022-09-12 11:30:34 +05:30 коммит произвёл GitHub
Родитель 43e88d02f5
Коммит 719d81a434
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 759 добавлений и 30 удалений

Просмотреть файл

@ -153,6 +153,32 @@ stages:
workingDirectory: $(WORK_DIR)
displayName: "Block Blob Coverage"
# Code Coverage with health monitor, dynamic, CPU and mem profilers enabled for block blob
- script: |
rm -rf $(MOUNT_DIR)/*
rm -rf $(TEMP_DIR)/*
cp $(BLOBFUSE2_CFG) /tmp/configBlockProfilerTemp.yaml
echo "dynamic-profile: true" >> /tmp/configBlockProfilerTemp.yaml
echo "cpu-profile: /tmp/cpuBlockProfTmp" >> /tmp/configBlockProfilerTemp.yaml
echo "mem-profile: /tmp/memBlockProfTmp" >> /tmp/configBlockProfilerTemp.yaml
echo "health_monitor:" >> /tmp/configBlockProfilerTemp.yaml
echo " enable-monitoring: true" >> /tmp/configBlockProfilerTemp.yaml
echo " monitor-disable-list:" >> /tmp/configBlockProfilerTemp.yaml
echo " - blobfuse_stats" >> /tmp/configBlockProfilerTemp.yaml
cat /tmp/configBlockProfilerTemp.yaml
./blobfuse2.test -test.v -test.coverprofile=$(WORK_DIR)/blobfuse2_block_profiler.cov mount $(MOUNT_DIR) --config-file=/tmp/configBlockProfilerTemp.yaml --foreground=true &
sleep 10
ps -aux | grep blobfuse2
rm -rf $(MOUNT_DIR)/*
cd test/e2e_tests
go test -v -timeout=7200s ./... -args -mnt-path=$(MOUNT_DIR) -tmp-path=$(TEMP_DIR)
cd -
sudo fusermount -u $(MOUNT_DIR)
sleep 5
workingDirectory: $(WORK_DIR)
displayName: "Block Blob Coverage with profilers"
- script: |
cd $(WORK_DIR)
$(WORK_DIR)/blobfuse2 gen-test-config --config-file=azure_key.yaml --container-name=$(containerName) --temp-path=$(TEMP_DIR) --output-file=$(BLOBFUSE2_ADLS_CFG)
@ -182,6 +208,32 @@ stages:
workingDirectory: $(WORK_DIR)
displayName: "ADLS Coverage"
# Code Coverage with health monitor, dynamic, CPU and mem profilers enabled for adls
- script: |
rm -rf $(MOUNT_DIR)/*
rm -rf $(TEMP_DIR)/*
cp $(BLOBFUSE2_ADLS_CFG) /tmp/configAdlsProfilerTemp.yaml
echo "dynamic-profile: true" >> /tmp/configAdlsProfilerTemp.yaml
echo "cpu-profile: /tmp/cpuAdlsProfTmp" >> /tmp/configAdlsProfilerTemp.yaml
echo "mem-profile: /tmp/memAdlsProfTmp" >> /tmp/configAdlsProfilerTemp.yaml
echo "health_monitor:" >> /tmp/configAdlsProfilerTemp.yaml
echo " enable-monitoring: true" >> /tmp/configAdlsProfilerTemp.yaml
echo " monitor-disable-list:" >> /tmp/configAdlsProfilerTemp.yaml
echo " - blobfuse_stats" >> /tmp/configAdlsProfilerTemp.yaml
cat /tmp/configAdlsProfilerTemp.yaml
./blobfuse2.test -test.v -test.coverprofile=$(WORK_DIR)/blobfuse2_adls_profiler.cov mount $(MOUNT_DIR) --config-file=/tmp/configAdlsProfilerTemp.yaml --foreground=true &
sleep 10
ps -aux | grep blobfuse2
rm -rf $(MOUNT_DIR)/*
cd test/e2e_tests
go test -v -timeout=7200s ./... -args -mnt-path=$(MOUNT_DIR) -tmp-path=$(TEMP_DIR)
cd -
sudo fusermount -u $(MOUNT_DIR)
sleep 5
workingDirectory: $(WORK_DIR)
displayName: "ADLS Coverage with profilers"
# -------------------------------------------------------
# Config Generation (Block Blob - LFU policy)

116
cmd/doc_test.go Normal file
Просмотреть файл

@ -0,0 +1,116 @@
/*
_____ _____ _____ ____ ______ _____ ------
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| --- | | | | |-----| |---- | | |-----| |----- ------
| | | | | | | | | | | | |
| ____| |_____ | ____| | ____| | |_____| _____| |_____ |_____
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
Copyright © 2020-2022 Microsoft Corporation. All rights reserved.
Author : <blobfusedev@microsoft.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
*/
package cmd
import (
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/Azure/azure-storage-fuse/v2/common"
"github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type docTestSuite struct {
suite.Suite
assert *assert.Assertions
}
func (suite *docTestSuite) SetupTest() {
suite.assert = assert.New(suite.T())
docCmdInput = struct{ outputLocation string }{}
options = mountOptions{}
err := log.SetDefaultLogger("silent", common.LogConfig{Level: common.ELogLevel.LOG_DEBUG()})
if err != nil {
panic("Unable to set silent logger as default.")
}
}
func (suite *docTestSuite) cleanupTest() {
resetCLIFlags(*docCmd)
}
func (suite *docTestSuite) TestDocsGeneration() {
defer suite.cleanupTest()
opDir := "/tmp/docs_" + randomString(6)
defer os.RemoveAll(opDir)
_, err := executeCommandC(rootCmd, "doc", fmt.Sprintf("--output-location=%s", opDir))
suite.assert.Nil(err)
files, err := os.ReadDir(opDir)
suite.assert.Nil(err)
suite.assert.NotZero(len(files))
}
func (suite *docTestSuite) TestOutputDirCreationError() {
defer suite.cleanupTest()
opDir := "/var/docs_" + randomString(6)
op, err := executeCommandC(rootCmd, "doc", fmt.Sprintf("--output-location=%s", opDir))
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to create output location")
}
func (suite *docTestSuite) TestDocsGenerationError() {
defer suite.cleanupTest()
opDir := "/var"
op, err := executeCommandC(rootCmd, "doc", fmt.Sprintf("--output-location=%s", opDir))
suite.assert.NotNil(err)
suite.assert.Contains(op, "cannot generate command tree")
}
func (suite *docTestSuite) TestOutputDirIsFileError() {
defer suite.cleanupTest()
opFile, err := ioutil.TempFile("", "docfile*")
suite.assert.Nil(err)
opFileName := opFile.Name()
opFile.Close()
defer os.Remove(opFileName)
op, err := executeCommandC(rootCmd, "doc", fmt.Sprintf("--output-location=%s", opFileName))
suite.assert.NotNil(err)
suite.assert.Contains(op, "output location is invalid as it is pointing to a file")
}
func TestDocCommand(t *testing.T) {
suite.Run(t, new(docTestSuite))
}

Просмотреть файл

@ -52,7 +52,6 @@ import (
"github.com/Azure/azure-storage-fuse/v2/common"
"github.com/Azure/azure-storage-fuse/v2/common/config"
"github.com/Azure/azure-storage-fuse/v2/common/exectime"
"github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/Azure/azure-storage-fuse/v2/internal"
@ -77,8 +76,6 @@ type mountOptions struct {
Components []string `config:"components"`
Foreground bool `config:"foreground"`
DefaultWorkingDir string `config:"default-working-dir"`
Debug bool `config:"debug"`
DebugPath string `config:"debug-path"`
CPUProfile string `config:"cpu-profile"`
MemProfile string `config:"mem-profile"`
PassPhrase string `config:"passphrase"`
@ -134,16 +131,6 @@ func (opt *mountOptions) validate(skipEmptyMount bool) error {
common.DefaultLogFilePath = filepath.Join(common.DefaultWorkDir, "blobfuse2.log")
}
if opt.Debug {
_, err := os.Stat(opt.DebugPath)
if os.IsNotExist(err) {
err := os.MkdirAll(opt.DebugPath, os.FileMode(0755))
if err != nil {
return fmt.Errorf("invalid debug path [%s]", err.Error())
}
}
}
return nil
}
@ -372,17 +359,6 @@ var mountCmd = &cobra.Command{
}
}
if options.Debug {
f, err := os.OpenFile(filepath.Join(options.DebugPath, "times.log"), os.O_CREATE|os.O_APPEND|os.O_RDWR, os.FileMode(0755))
if err != nil {
fmt.Printf("Unable to open times.log file for exectime reporting [%s]", err.Error())
}
exectime.SetDefault(f, true)
} else {
exectime.SetDefault(nil, false)
}
defer exectime.PrintStats()
config.Set("mount-path", options.MountPath)
var pipeline *internal.Pipeline

383
cmd/mount_test.go Normal file
Просмотреть файл

@ -0,0 +1,383 @@
/*
_____ _____ _____ ____ ______ _____ ------
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| --- | | | | |-----| |---- | | |-----| |----- ------
| | | | | | | | | | | | |
| ____| |_____ | ____| | ____| | |_____| _____| |_____ |_____
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
Copyright © 2020-2022 Microsoft Corporation. All rights reserved.
Author : <blobfusedev@microsoft.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
*/
package cmd
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/Azure/azure-storage-fuse/v2/common"
"github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
var configMountTest string = `
logging:
type: syslog
default-working-dir: /tmp/blobfuse2
file_cache:
path: /tmp/fileCachePath
libfuse:
attribute-expiration-sec: 120
entry-expiration-sec: 60
azstorage:
account-name: myAccountName
account-key: myAccountKey
mode: key
endpoint: myEndpoint
container: myContainer
components:
- libfuse
- file_cache
- attr_cache
- azstorage
health_monitor:
monitor-disable-list:
- network_profiler
- blobfuse_stats
`
var configMountLoopback string = `
logging:
type: syslog
default-working-dir: /tmp/blobfuse2
components:
- libfuse
- loopbackfs
libfuse:
attribute-expiration-sec: 120
entry-expiration-sec: 60
loopbackfs:
path: /tmp/bfuseloopback
`
var confFileMntTest string
type mountTestSuite struct {
suite.Suite
assert *assert.Assertions
}
func (suite *mountTestSuite) SetupTest() {
suite.assert = assert.New(suite.T())
options = mountOptions{}
err := log.SetDefaultLogger("silent", common.LogConfig{Level: common.ELogLevel.LOG_DEBUG()})
if err != nil {
panic("Unable to set silent logger as default.")
}
}
func (suite *mountTestSuite) cleanupTest() {
resetCLIFlags(*mountCmd)
}
// mount failure test where the mount directory does not exists
func (suite *mountTestSuite) TestMountDirNotExists() {
defer suite.cleanupTest()
tempDir := randomString(8)
op, err := executeCommandC(rootCmd, "mount", tempDir, fmt.Sprintf("--config-file=%s", confFileMntTest))
suite.assert.NotNil(err)
suite.assert.Contains(op, "mount directory does not exists")
}
// mount failure test where the mount directory is not empty
func (suite *mountTestSuite) TestMountDirNotEmpty() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
tempDir := filepath.Join(mntDir, "tempdir")
err = os.MkdirAll(tempDir, 0777)
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--config-file=%s", confFileMntTest))
suite.assert.NotNil(err)
suite.assert.Contains(op, "mount directory is not empty")
}
// mount failure test where the mount path is not provided
func (suite *mountTestSuite) TestMountPathNotProvided() {
defer suite.cleanupTest()
op, err := executeCommandC(rootCmd, "mount", "", fmt.Sprintf("--config-file=%s", confFileMntTest))
suite.assert.NotNil(err)
suite.assert.Contains(op, "mount path not provided")
}
// mount failure test where the config file type is unsupported
func (suite *mountTestSuite) TestUnsupportedConfigFileType() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
op, err := executeCommandC(rootCmd, "mount", mntDir, "--config-file=cfgInvalid.yam")
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid config file")
suite.assert.Contains(op, "Unsupported Config Type")
}
// mount failure test where the config file is not present
func (suite *mountTestSuite) TestConfigFileNotFound() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
op, err := executeCommandC(rootCmd, "mount", mntDir, "--config-file=cfgNotFound.yaml")
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid config file")
suite.assert.Contains(op, "no such file or directory")
}
// mount failure test where config file is not provided
func (suite *mountTestSuite) TestConfigFileNotProvided() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
op, err := executeCommandC(rootCmd, "mount", mntDir)
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to initialize new pipeline")
}
func (suite *mountTestSuite) TestDefaultConfigFile() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
currDir, err := os.Getwd()
suite.assert.Nil(err)
defaultCfgPath := filepath.Join(currDir, common.DefaultConfigFilePath)
// create default config file
src, err := os.Open(confFileMntTest)
suite.Equal(nil, err)
dest, err := os.Create(defaultCfgPath)
suite.Equal(nil, err)
defer os.Remove(defaultCfgPath)
bytesCopied, err := io.Copy(dest, src)
suite.Equal(nil, err)
suite.NotEqual(0, bytesCopied)
err = dest.Close()
suite.Equal(nil, err)
err = src.Close()
suite.Equal(nil, err)
op, err := executeCommandC(rootCmd, "mount", mntDir)
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to initialize new pipeline")
}
func (suite *mountTestSuite) TestInvalidLogLevel() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--config-file=%s", confFileMntTest), "--log-level=debug")
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid log level")
}
func (suite *mountTestSuite) TestCliParamsV1() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
tempLogDir := "/tmp/templogs_" + randomString(6)
defer os.RemoveAll(tempLogDir)
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--config-file=%s", confFileMntTest),
fmt.Sprintf("--log-file-path=%s", tempLogDir+"/blobfuse2.log"), "--invalidate-on-sync", "--pre-mount-validate", "--basic-remount-check")
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to initialize new pipeline")
}
func (suite *mountTestSuite) TestStreamAttrCacheOptionsV1() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
tempLogDir := "/tmp/templogs_" + randomString(6)
defer os.RemoveAll(tempLogDir)
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--log-file-path=%s", tempLogDir+"/blobfuse2.log"),
"--streaming", "--use-attr-cache", "--invalidate-on-sync", "--pre-mount-validate", "--basic-remount-check")
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to initialize new pipeline")
}
// libfuse options test
func (suite *mountTestSuite) TestLibfuseOptions() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
tempLogDir := "/tmp/templogs_" + randomString(6)
defer os.RemoveAll(tempLogDir)
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--config-file=%s", confFileMntTest),
fmt.Sprintf("--log-file-path=%s", tempLogDir+"/blobfuse2.log"), "--invalidate-on-sync", "--pre-mount-validate", "--basic-remount-check",
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o allow_root", "-o default_permissions", "-o umask=755")
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to initialize new pipeline")
}
// mount failure test where libfuse options are greater than 8
func (suite *mountTestSuite) TestLibfuseOptionsMoreThan8() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
// greater than 8 libfuse options
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--config-file=%s", confFileMntTest),
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o allow_root", "-o default_permissions", "-o umask=755", "-o random_option")
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid FUSE options")
}
// mount failure test where a libfuse option is incorrect
func (suite *mountTestSuite) TestInvalidLibfuseOption() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
// incorrect option
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--config-file=%s", confFileMntTest),
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o default_permissions", "-o umask=755", "-o a=b=c")
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid FUSE options")
}
// mount failure test where a libfuse option is undefined
func (suite *mountTestSuite) TestUndefinedLibfuseOption() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
// undefined option
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--config-file=%s", confFileMntTest),
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o allow_root", "-o umask=755", "-o random_option")
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid FUSE options")
}
// mount failure test where umask value is invalid
func (suite *mountTestSuite) TestInvalidUmaskValue() {
defer suite.cleanupTest()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
// incorrect umask value
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--config-file=%s", confFileMntTest),
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o allow_root", "-o default_permissions", "-o umask=abcd")
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to parse umask")
}
func (suite *mountTestSuite) TestMountUsingLoopbackFailure() {
defer suite.cleanupTest()
confFile, err := ioutil.TempFile("", "conf*.yaml")
suite.assert.Nil(err)
confFileName := confFile.Name()
defer os.Remove(confFileName)
_, err = confFile.WriteString(configMountLoopback)
suite.assert.Nil(err)
confFile.Close()
mntDir, err := ioutil.TempDir("", "mntdir")
suite.assert.Nil(err)
defer os.RemoveAll(mntDir)
op, err := executeCommandC(rootCmd, "mount", mntDir, fmt.Sprintf("--config-file=%s", confFileName))
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to daemonize application")
}
func TestMountCommand(t *testing.T) {
confFile, err := ioutil.TempFile("", "conf*.yaml")
if err != nil {
t.Error("Failed to create config file")
}
confFileMntTest = confFile.Name()
defer os.Remove(confFileMntTest)
_, err = confFile.WriteString(configMountTest)
if err != nil {
t.Error("Failed to write to config file")
}
confFile.Close()
suite.Run(t, new(mountTestSuite))
}

Просмотреть файл

@ -64,6 +64,7 @@ type generateConfigTestSuite struct {
func (suite *generateConfigTestSuite) SetupTest() {
suite.assert = assert.New(suite.T())
libfuseOptions = make([]string, 0)
err := log.SetDefaultLogger("silent", common.LogConfig{Level: common.ELogLevel.LOG_DEBUG()})
if err != nil {
panic("Unable to set silent logger as default.")
@ -97,12 +98,6 @@ func TestGenerateConfig(t *testing.T) {
suite.Run(t, new(generateConfigTestSuite))
}
func (suite *generateConfigTestSuite) TestHelp() {
defer suite.cleanupTest()
_, err := executeCommandC(rootCmd, "mountv1", "--convert-config-only=true", "-h")
suite.assert.Nil(err)
}
func randomString(length int) string {
rand.Seed(time.Now().UnixNano())
b := make([]byte, length)
@ -771,3 +766,210 @@ func (suite *generateConfigTestSuite) TestCLIParamPreMountValidateNoError() {
_, err := executeCommandC(rootCmd, "mountv1", "--convert-config-only=true", outputFile, download, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()))
suite.assert.Nil(err)
}
// libfuse options test
func (suite *generateConfigTestSuite) TestLibfuseOptions() {
defer suite.cleanupTest()
name := generateFileName()
v1ConfigFile, _ := ioutil.TempFile("", name+".tmp.cfg")
defer os.Remove(v1ConfigFile.Name())
v1ConfigFile.WriteString("accountName myAccountName")
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
_, err := executeCommandC(rootCmd, "mountv1", "--convert-config-only=true", outputFile, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()),
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o allow_root", "-o default_permissions", "-o umask=755")
suite.assert.Nil(err)
}
// mountv1 failure test where libfuse options are greater than 8
func (suite *generateConfigTestSuite) TestLibfuseOptionsMoreThan8() {
defer suite.cleanupTest()
name := generateFileName()
v1ConfigFile, _ := ioutil.TempFile("", name+".tmp.cfg")
defer os.Remove(v1ConfigFile.Name())
v1ConfigFile.WriteString("accountName myAccountName")
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
// greater than 8 libfuse options
op, err := executeCommandC(rootCmd, "mountv1", "--convert-config-only=true", outputFile, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()),
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o allow_root", "-o default_permissions", "-o umask=755", "-o random_option")
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid FUSE options")
}
// mountv1 failure test where a libfuse option is incorrect
func (suite *generateConfigTestSuite) TestInvalidLibfuseOption() {
defer suite.cleanupTest()
name := generateFileName()
v1ConfigFile, _ := ioutil.TempFile("", name+".tmp.cfg")
defer os.Remove(v1ConfigFile.Name())
v1ConfigFile.WriteString("accountName myAccountName")
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
// incorrect option
op, err := executeCommandC(rootCmd, "mountv1", "--convert-config-only=true", outputFile, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()),
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o default_permissions", "-o umask=755", "-o a=b=c")
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid FUSE options")
}
// mountv1 failure test where a libfuse option is undefined
func (suite *generateConfigTestSuite) TestUndefinedLibfuseOption() {
defer suite.cleanupTest()
name := generateFileName()
v1ConfigFile, _ := ioutil.TempFile("", name+".tmp.cfg")
defer os.Remove(v1ConfigFile.Name())
v1ConfigFile.WriteString("accountName myAccountName")
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
// undefined option
op, err := executeCommandC(rootCmd, "mountv1", "--convert-config-only=true", outputFile, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()),
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o allow_root", "-o umask=755", "-o random_option")
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid FUSE options")
}
// mountv1 failure test where umask value is invalid
func (suite *generateConfigTestSuite) TestInvalidUmaskValue() {
defer suite.cleanupTest()
name := generateFileName()
v1ConfigFile, _ := ioutil.TempFile("", name+".tmp.cfg")
defer os.Remove(v1ConfigFile.Name())
v1ConfigFile.WriteString("accountName myAccountName")
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
// incorrect umask value
op, err := executeCommandC(rootCmd, "mountv1", "--convert-config-only=true", outputFile, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()),
"-o allow_other", "-o attr_timeout=120", "-o entry_timeout=120", "-o negative_timeout=120",
"-o ro", "-o allow_root", "-o default_permissions", "-o umask=abcd")
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to parse umask")
}
// mountv1 failure test where attr_timeout value is invalid
func (suite *generateConfigTestSuite) TestInvalidAttrTimeout() {
defer suite.cleanupTest()
name := generateFileName()
v1ConfigFile, _ := ioutil.TempFile("", name+".tmp.cfg")
defer os.Remove(v1ConfigFile.Name())
v1ConfigFile.WriteString("accountName myAccountName")
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
tempDir := randomString(6)
// incorrect attr_timeout value
op, err := executeCommandC(rootCmd, "mountv1", tempDir, "--convert-config-only=true", outputFile, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()),
"-o allow_other=false", "-o entry_timeout=120", "-o negative_timeout=120", "-o ro",
"-o allow_root", "-o default_permissions", "-o umask=755", "-o attr_timeout=abcd")
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to parse attr_timeout")
}
// mountv1 failure test where entry_timeout value is invalid
func (suite *generateConfigTestSuite) TestInvalidEntryTimeout() {
defer suite.cleanupTest()
name := generateFileName()
v1ConfigFile, _ := ioutil.TempFile("", name+".tmp.cfg")
defer os.Remove(v1ConfigFile.Name())
v1ConfigFile.WriteString("accountName myAccountName")
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
tempDir := randomString(6)
// incorrect entry_timeout value
op, err := executeCommandC(rootCmd, "mountv1", tempDir, "--convert-config-only=true", outputFile, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()),
"-o allow_other=false", "-o attr_timeout=120", "-o negative_timeout=120", "-o ro",
"-o allow_root", "-o default_permissions", "-o umask=755", "-o entry_timeout=abcd")
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to parse entry_timeout")
}
// mountv1 failure test where negative_timeout value is invalid
func (suite *generateConfigTestSuite) TestInvalidNegativeTimeout() {
defer suite.cleanupTest()
name := generateFileName()
v1ConfigFile, _ := ioutil.TempFile("", name+".tmp.cfg")
defer os.Remove(v1ConfigFile.Name())
v1ConfigFile.WriteString("accountName myAccountName")
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
tempDir := randomString(6)
// incorrect negative_timeout value
op, err := executeCommandC(rootCmd, "mountv1", tempDir, "--convert-config-only=true", outputFile, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()),
"-o allow_other=false", "-o entry_timeout=120", "-o attr_timeout=120", "-o ro",
"-o allow_root", "-o default_permissions", "-o umask=755", "-o negative_timeout=abcd")
suite.assert.NotNil(err)
suite.assert.Contains(op, "failed to parse negative_timeout")
}
func (suite *generateConfigTestSuite) TestEnvVarAccountName() {
defer suite.cleanupTest()
name := generateFileName()
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
tempDir := randomString(6)
os.Setenv("AZURE_STORAGE_ACCOUNT", "myAccountName")
defer os.Unsetenv("AZURE_STORAGE_ACCOUNT")
_, err := executeCommandC(rootCmd, "mountv1", tempDir, "--convert-config-only=true", outputFile)
suite.assert.Nil(err)
}
func (suite *generateConfigTestSuite) TestEnvVarAccountNameError() {
defer suite.cleanupTest()
name := generateFileName()
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
tempDir := randomString(6)
op, err := executeCommandC(rootCmd, "mountv1", tempDir, "--convert-config-only=true", outputFile)
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid account name")
}
func (suite *generateConfigTestSuite) TestInvalidAccountType() {
defer suite.cleanupTest()
name := generateFileName()
v1ConfigFile, _ := ioutil.TempFile("", name+".tmp.cfg")
defer os.Remove(v1ConfigFile.Name())
v1ConfigFile.WriteString("accountName myAccountName\naccountType random")
v2ConfigFile, _ := ioutil.TempFile("", name+".tmp.yaml")
defer os.Remove(v2ConfigFile.Name())
outputFile := fmt.Sprintf("--output-file=%s", v2ConfigFile.Name())
tempDir := randomString(6)
op, err := executeCommandC(rootCmd, "mountv1", tempDir, "--convert-config-only=true", outputFile, fmt.Sprintf("--config-file=%s", v1ConfigFile.Name()))
suite.assert.NotNil(err)
suite.assert.Contains(op, "invalid account type")
}