Files
kubevela/pkg/utils/file_test.go
Charlie Chiang f8833e34bc Feat: implement addon init command (#4162)
* Feat: implement addon create command

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>

* Refactor: make global vars local

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>

* Style: fix typos

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>

* Test: create test for file utils

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>

* Feat: use -p flag to manually specify paths

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>

* Refactor: make changes according to comments

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>

* Feat: create empty scaffold if Chart-related paramaters are not provided

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>

* Refactor: fix golangci-lint warnings

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>

* Test: add cli tests

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>

* Feat: show URL in errors if an invalid URL is detected

Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
2022-06-24 14:25:36 +08:00

48 lines
1.3 KiB
Go

/*
Copyright 2022 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utils
import (
"os"
"path/filepath"
"testing"
"gotest.tools/assert"
)
func TestIsEmptyDir(t *testing.T) {
// Test with an empty dir
err := os.Mkdir("testdir", 0750)
assert.NilError(t, err)
defer func() {
_ = os.RemoveAll("testdir")
}()
isEmptyDir, err := IsEmptyDir("testdir")
assert.Equal(t, isEmptyDir, true)
assert.NilError(t, err)
// Test with a file
err = os.WriteFile(filepath.Join("testdir", "testfile"), []byte("test"), 0644)
assert.NilError(t, err)
isEmptyDir, err = IsEmptyDir(filepath.Join("testdir", "testfile"))
assert.Equal(t, isEmptyDir, false)
assert.Equal(t, err != nil, true)
// Test with a non-empty dir
isEmptyDir, err = IsEmptyDir("testdir")
assert.Equal(t, isEmptyDir, false)
assert.NilError(t, err)
}