Skip to content

Commit

Permalink
Try to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
peremato committed May 30, 2024
1 parent a7add83 commit 266899f
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 25 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https:///JuliaHEP.github.io/XRootD.jl/dev/)
[![Build Status](https://github.com/JuliaHEP/XRootD.jl/workflows/CI/badge.svg)](https://github.com/JuliaHEP/XRootD.jl/actions)
[[![License](https://img.shields.io/badge/license-LGPL-blue.svg)](LICENSE)
[![codecov](https://codecov.io/gh/JuliaHEP/XRootD.jl/graph/badge.svg?token=AS74WXOYT6)](https://codecov.io/gh/JuliaHEP/XRootD.jl)
[![License](https://img.shields.io/badge/license-LGPL-blue.svg)](LICENSE)

## Description

Expand Down
155 changes: 133 additions & 22 deletions src/Responses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ export OpenFlags, DirListFlags, QueryCode, Access
const URL = XRootD.XrdCl!URL
const StatInfo = XRootD.XrdCl!StatInfo
const LocationInfo = XRootD.XrdCl!LocationInfo
const Location = XRootD.XrdCl!LocationInfo!Location
const ProtocolInfo = XRootD.XrdCl!ProtocolInfo
const XRootDStatus = XRootD.XrdCl!XRootDStatus
const Status = XRootD.XrdCl!Status


module OpenFlags
Expand Down Expand Up @@ -69,11 +71,27 @@ module QueryCode
const XAttr = XRootD.XrdCl!QueryCode!XAttr
end

#---XRootDStatus interface---------------------------------------------------------------------
#---XRootDStatus and Status interface----------------------------------------------------------
Base.show(io::IO, status::XRootDStatus) = print(io, XRootD.ToStr(status))
isOK(status::XRootDStatus) = XRootD.IsOK(status)
isError(status::XRootDStatus) = XRootD.IsError(status)
isFatal(status::XRootDStatus) = XRootD.IsFatal(status)
Base.show(io::IO, status::Status) = print(io, XRootD.ToString(status))
"""
isOK(status::Status)
Check if the status is OK.
"""
isOK(status::Status) = XRootD.IsOK(status)
"""
isError(status::Status)
Check if the status is an error.
"""
isError(status::Status) = XRootD.IsError(status)
"""
isFatal(status::Status)
Check if the status is fatal.
"""
isFatal(status::Status) = XRootD.IsFatal(status)

#---StatInfo interface-------------------------------------------------------------------------
function Base.show(io::IO, s::StatInfo)
Expand All @@ -84,46 +102,139 @@ function Base.show(io::IO, s::StatInfo)
date = XRootD.GetModTimeAsString(s)
print(io, "[$mode $owner $group $size $date]")
end
"""
getFlags(statinfo::StatInfo)
The flags of the stat info.
"""
getFlags(statinfo::StatInfo) = XRootD.GetFlags(statinfo)
"""
Base.isdir(statinfo::StatInfo)
Check if the stat info is a directory.
"""
Base.isdir(statinfo::StatInfo) = XRootD.GetFlags(statinfo) & XRootD.XrdCl!StatInfo!IsDir != 0
"""
Base.isfile(statinfo::StatInfo)
Check if the stat info is a file.
"""
Base.isfile(statinfo::StatInfo) = XRootD.GetFlags(statinfo) & (XRootD.XrdCl!StatInfo!IsDir | XRootD.XrdCl!StatInfo!Other) == 0
"""
Base.isreadable(statinfo::StatInfo)
Check if the stat info is readable.
"""
Base.isreadable(statinfo::StatInfo) = XRootD.GetFlags(statinfo) & XRootD.XrdCl!StatInfo!IsReadable != 0
"""
Base.iswritable(statinfo::StatInfo)
Check if the stat info is writable.
"""
Base.iswritable(statinfo::StatInfo) = XRootD.GetFlags(statinfo) & XRootD.XrdCl!StatInfo!IsWritable != 0
"""
isExecutable(statinfo::StatInfo)
Check if the stat info is executable.
"""
isExecutable(statinfo::StatInfo) = XRootD.GetFlags(statinfo) & XRootD.XrdCl!StatInfo!XBitSet != 0
"""
isOffline(statinfo::StatInfo)
Check if the stat info is offline.
"""
isOffline(statinfo::StatInfo) = XRootD.GetFlags(statinfo) & XRootD.XrdCl!StatInfo!Offline != 0
"""
Base.getproperty(statinfo::StatInfo, prop::Symbol)
Get the property of the stat info.
# Arguments
- `statinfo::StatInfo`: the stat info.
- `prop::Symbol`: the property to get (examples: `:size`, `:owner`, `:group`, `:modtime`, `:flags`, `:octmode`, `:mode`).
"""
function Base.getproperty(statinfo::StatInfo, prop::Symbol)
if prop == :size
return XRootD.GetSize(statinfo)
elseif prop == :owner
return XRootD.GetOwner(statinfo)
elseif prop == :group
return XRootD.GetGroup(statinfo)
elseif prop == :modtime
return XRootD.GetModTime(statinfo)
elseif prop == :flags
return XRootD.GetFlags(statinfo)
elseif prop == :octmode
return XRootD.GetModeAsOctString(statinfo)
elseif prop == :mode
return XRootD.GetModeAsString(statinfo) |> String
else
return getfield(statinfo, prop)
end
if prop == :size
return XRootD.GetSize(statinfo)
elseif prop == :owner
return XRootD.GetOwner(statinfo) |> String
elseif prop == :group
return XRootD.GetGroup(statinfo) |> String
elseif prop == :modtime
return XRootD.GetModTime(statinfo)
elseif prop == :modtime_str
return XRootD.GetModTimeAsString(statinfo)
elseif prop == :changetime
return XRootD.GetChangeTime(statinfo)
elseif prop == :changetime_str
return XRootD.GetChangeTimeAsString(statinfo)
elseif prop == :accesstime
return XRootD.GetAccessTime(statinfo)
elseif prop == :accesstime_str
return XRootD.GetAccessTimeAsString(statinfo)
elseif prop == :flags
return XRootD.GetFlags(statinfo)
elseif prop == :octmode
return XRootD.GetModeAsOctString(statinfo)
elseif prop == :mode
return XRootD.GetModeAsString(statinfo) |> String
else
return getfield(statinfo, prop)
end
end

#---LocationInfo interface---------------------------------------------------------------------
function Base.show(io::IO, l::XRootD.XrdCl!LocationInfo!Location)
function Base.show(io::IO, l::Location)
address = XRootD.GetAddress(l) |> String
type = XRootD.GetType(l) |> UInt32
acct = XRootD.GetAccessType(l) |> UInt32
manager = XRootD.IsManager(l) |> string
server = XRootD.IsServer(l) |> string
print(io, "<type: $type, address: $address, accesstype: $acct, is_manager: $manager, is_server: $server>")
end
"""
Base.getproperty(l::Location, prop::Symbol)
Get the property of the location.
# Arguments
- `l::Location`: the location.
- `prop::Symbol`: the property to get (examples: `:address`, `:type`, `:accesstype`, `:is_manager`, `:is_server`).
"""
function Base.getproperty(l::Location, prop::Symbol)
if prop == :address
return XRootD.GetAddress(l) |> String
elseif prop == :type
return XRootD.GetType(l) |> UInt32
elseif prop == :accesstype
return XRootD.GetAccessType(l) |> UInt32
elseif prop == :is_manager
return XRootD.IsManager(l)
elseif prop == :is_server
return XRootD.IsServer(l)
else
return getfield(l, prop)
end
end

#---ProtocolInfo interface---------------------------------------------------------------------
function Base.show(io::IO, p::XRootD.XrdCl!ProtocolInfo)
info = XRootD.GetHostInfo(p)
version = XRootD.GetVersion(p)
print(io, "<hostinfo: $info, version: $version>")
end
"""
Base.getproperty(p::ProtocolInfo, prop::Symbol)
Get the property of the protocol info.
# Arguments
- `p::ProtocolInfo`: the protocol info.
- `prop::Symbol`: the property to get (examples: `:hostinfo`, `:version`).
"""
function Base.getproperty(p::ProtocolInfo, prop::Symbol)
if prop == :hostinfo
return XRootD.GetHostInfo(p)
elseif prop == :version
return XRootD.GetVersion(p)
else
return getfield(p, prop)
end
end
21 changes: 20 additions & 1 deletion test/testFile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using XRootD.XrdCl
f = File()
st, response = open(f, "root://localhost:1094//tmp/new_testfile", OpenFlags.Write|OpenFlags.Delete)
@test isOK(st)
@test isopen(f)
st, response = truncate(f, 0)
@test isOK(st)
st, statinfo = stat(f)
Expand Down Expand Up @@ -46,6 +47,21 @@ using XRootD.XrdCl
@test isOK(st)
@test buffer == Vector{UInt8}(data)

# Read more than the file size
st, buffer = read(f, statinfo.size + 100)
@test isOK(st)
@test length(buffer) == statinfo.size

# Read with offset
st, buffer = read(f, 5, 5)
@test isOK(st)
@test buffer == Vector{UInt8}("D:Hel")

# Read beyond the file size
st, buffer = read(f, 100, 100)
@test isOK(st)
@test length(buffer) == 0

# Close the file
st, response = close(f)
@test isOK(st)
Expand Down Expand Up @@ -76,12 +92,15 @@ using XRootD.XrdCl
st, response = close(f)
@test isOK(st)

# Open the file for reading lines
st, response = open(f, "root://localhost:1094//tmp/testfile3", OpenFlags.Read)
@test isOK(st)
st, lines = readlines(f)
@test isOK(st)
@test lines == ["Hello\n", "World\n", "Folks!"]

st, response = close(f)
@test isOK(st)
@test !isopen(f)


end
19 changes: 18 additions & 1 deletion test/testFileSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ using XRootD.XrdCl
@test isOK(st)
st, result = copy(fs, "/tmp/testfile", "/tmp/testfile2", force=true)
@test isOK(st)
@test isfile("/tmp/testfile2")
@test isfile("/tmp/testfile2") # Check if the file was copied

# test stat of newly copied file
st, statinfo2 = stat(fs, "/tmp/testfile2")
isOK(st)
isfile(statinfo2)
@test statinfo.size == 13
@test isreadable(statinfo2)
@test iswritable(statinfo2)
@test !isdir(statinfo2)
@test !isExecutable(statinfo2)
@test !isOffline(statinfo2)
@test statinfo2.owner == statinfo.owner
@test statinfo2.group == statinfo.group
@test statinfo2.modtime == statinfo.modtime
@test statinfo2.flags == statinfo.flags
@test statinfo2.octmode[1:3] == statinfo.octmode[1:3] # owner permissions the same


# Locate
st , locations = locate(fs, "/tmp", OpenFlags.Refresh)
Expand Down

0 comments on commit 266899f

Please sign in to comment.