From bfccc88a8c266aaf2a2ea8895f72c23c0028488f Mon Sep 17 00:00:00 2001 From: Mohammad Date: Fri, 28 Apr 2023 12:29:58 +0330 Subject: [PATCH] feat(utils): impl current dir --- pkg/utils/file.go | 4 ++++ pkg/utils/file_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/utils/file.go b/pkg/utils/file.go index fc69606..fc3d92d 100644 --- a/pkg/utils/file.go +++ b/pkg/utils/file.go @@ -27,3 +27,7 @@ func StoreFile(name string, contents string) error { return nil } + +func CurrenDir() (string, error) { + return os.Getwd() +} diff --git a/pkg/utils/file_test.go b/pkg/utils/file_test.go index 91765b6..d8857cf 100644 --- a/pkg/utils/file_test.go +++ b/pkg/utils/file_test.go @@ -36,3 +36,19 @@ func TestStoreFile(t *testing.T) { t.Errorf("unexpected file contents: got %s, want %s", actual, contents) } } + +func TestCurrenDir(t *testing.T) { + expectedDir, err := os.Getwd() + if err != nil { + t.Fatalf("Error getting current directory: %s", err) + } + + actualDir, err := utils.CurrenDir() + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + if actualDir != expectedDir { + t.Errorf("Expected directory '%s', but got '%s'", expectedDir, actualDir) + } +}