You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "Xuanwo (via GitHub)" <gi...@apache.org> on 2023/06/17 11:15:06 UTC

[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2475: feat(bindings/haskell): support `is_exist` `create_dir` `copy` `rename` `delete`

Xuanwo commented on code in PR #2475:
URL: https://github.com/apache/incubator-opendal/pull/2475#discussion_r1233023320


##########
bindings/haskell/haskell-src/OpenDAL.hs:
##########
@@ -28,16 +33,48 @@ import Data.HashMap.Strict (HashMap)
 import qualified Data.HashMap.Strict as HashMap
 import Foreign
 import Foreign.C.String
+import Foreign.C.Types (CChar)
 import OpenDAL.FFI
 
-newtype Operator = Operator (Ptr RawOperator)
+newtype Operator = Operator (ForeignPtr RawOperator)
+
+data ErrorCode
+  = FFIError
+  | Unexpected
+  | Unsupported
+  | ConfigInvalid
+  | NotFound
+  | PermissionDenied
+  | IsADirectory
+  | NotADirectory
+  | AlreadyExists
+  | RateLimited
+  | IsSameFile
+  deriving (Eq, Show)
+
+data OpenDALError = OpenDALError {errorCode :: ErrorCode, message :: String}

Review Comment:
   I prefer to not add `OpenDAL` prefix for struct in binding. Is `Error` reserved in hashell?



##########
bindings/haskell/test/BasicTest.hs:
##########
@@ -27,15 +27,40 @@ basicTests :: TestTree
 basicTests =
   testGroup
     "Basic Tests"
-    [ testCase "read and write to memory" testReadAndWriteToMemory
+    [ testCase "test-memory" testMemory
+    , testCase "test-fs" testFs
     ]
 
-testReadAndWriteToMemory :: Assertion
-testReadAndWriteToMemory = do
-  Right op <- createOp "memory" HashMap.empty
-  _ <- writeOp op "key1" "value1"
-  _ <- writeOp op "key2" "value2"
-  value1 <- readOp op "key1"
-  value2 <- readOp op "key2"
-  value1 @?= Right "value1"
-  value2 @?= Right "value2"
\ No newline at end of file
+testMemory :: Assertion
+testMemory = do
+  Right op <- newOp "memory" $ HashMap.empty
+  writeOp op "key1" "value1" >>= (@?= Right ())
+  writeOp op "key2" "value2" >>= (@?= Right ())
+  readOp op "key1" >>= (@?= Right "value1")
+  readOp op "key2" >>= (@?= Right "value2")
+  isExistOp op "key1" >>= (@?= Right True)
+  isExistOp op "key2" >>= (@?= Right True)
+  createDirOp op "dir1/" >>= (@?= Right ())
+  isExistOp op "dir1/" >>= (@?= Right True)
+  deleteOp op "key1" >>= (@?= Right ())
+  isExistOp op "key1" >>= (@?= Right False)
+
+testFs :: Assertion
+testFs = do

Review Comment:
   Please don't add tests for specific services. This should be covered by Rust core.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org