feat: Enhance Script Details and Add MacOS Compatibility with Documentation Updates (#1794)

* feat: fix a portion of get path

* feat: optimize mac deployment scripts
This commit is contained in:
Xinwei Xiong
2024-01-21 10:49:08 +08:00
committed by GitHub
parent 907104701a
commit 7155d1acb7
10 changed files with 138 additions and 24 deletions
+27
View File
@@ -0,0 +1,27 @@
package genutil
import (
"fmt"
"os"
"path/filepath"
)
// OutDir creates the absolute path name from path and checks path exists.
// Returns absolute path including trailing '/' or error if path does not exist.
func OutDir(path string) (string, error) {
outDir, err := filepath.Abs(path)
if err != nil {
return "", err
}
stat, err := os.Stat(outDir)
if err != nil {
return "", err
}
if !stat.IsDir() {
return "", fmt.Errorf("output directory %s is not a directory", outDir)
}
outDir += "/"
return outDir, nil
}
+26
View File
@@ -0,0 +1,26 @@
package genutil
import (
"testing"
)
func TestValidDir(t *testing.T) {
_, err := OutDir("./")
if err != nil {
t.Fatal(err)
}
}
func TestInvalidDir(t *testing.T) {
_, err := OutDir("./nondir")
if err == nil {
t.Fatal("expected an error")
}
}
func TestNotDir(t *testing.T) {
_, err := OutDir("./genutils_test.go")
if err == nil {
t.Fatal("expected an error")
}
}