1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
# frozen_string_literal: true
############################################################################
# sys_proctable_windows_spec.rb
#
# Test suite for the sys-proctable library for MS Windows. This should be
# run via the 'rake spec' task.
############################################################################
require 'spec_helper'
require 'socket'
RSpec.describe Sys::ProcTable, :windows do
let(:hostname) { Socket.gethostname }
let(:fields) {
%w[
caption
cmdline
comm
creation_class_name
creation_date
cs_creation_class_name
cs_name description
executable_path
execution_state
handle
handle_count
install_date
kernel_mode_time
maximum_working_set_size
minimum_working_set_size name
os_creation_class_name
os_name
other_operation_count
other_transfer_count
page_faults
page_file_usage
ppid
peak_page_file_usage
peak_virtual_size
peak_working_set_size
priority
private_page_count
pid
quota_non_paged_pool_usage
quota_paged_pool_usage
quota_peak_non_paged_pool_usage
quota_peak_paged_pool_usage
read_operation_count
read_transfer_count
session_id
status
termination_date
thread_count
user_mode_time
virtual_size
windows_version
working_set_size
write_operation_count
write_transfer_count
]
}
context 'fields' do
it 'responds to a fields method' do
expect(described_class).to respond_to(:fields)
end
it 'returns the expected results for the fields method' do
expect(described_class.fields).to be_kind_of(Array)
expect(described_class.fields).to eql(fields)
end
end
context 'ps' do
it 'accepts an optional host' do
expect{ described_class.ps(:host => hostname) }.not_to raise_error
end
it 'ignores unused options' do
expect{ described_class.ps(:smaps => false) }.not_to raise_error
end
end
context 'ProcTable::Struct members' do
subject(:process){ described_class.ps.first }
it 'has a write_transfer_count struct member with the expected data type' do
expect(process).to respond_to(:write_transfer_count)
expect(process.write_transfer_count).to be_kind_of(Integer)
end
it 'has a write_operation_count struct member with the expected data type' do
expect(process).to respond_to(:write_operation_count)
expect(process.write_operation_count).to be_kind_of(Integer)
end
it 'has a working_set_size struct member with the expected data type' do
expect(process).to respond_to(:working_set_size)
expect(process.working_set_size).to be_kind_of(Integer)
end
it 'has a windows_version struct member with the expected data type' do
expect(process).to respond_to(:windows_version)
expect(process.windows_version).to be_kind_of(String)
end
it 'has a virtual_size struct member with the expected data type' do
expect(process).to respond_to(:virtual_size)
expect(process.virtual_size).to be_kind_of(Integer)
end
it 'has a user_mode_time struct member with the expected data type' do
expect(process).to respond_to(:user_mode_time)
expect(process.user_mode_time).to be_kind_of(Integer)
end
it 'has a thread_count struct member with the expected data type' do
expect(process).to respond_to(:thread_count)
expect(process.thread_count).to be_kind_of(Integer)
end
it 'has a termination_date struct member with the expected data type' do
expect(process).to respond_to(:termination_date)
expect(process.termination_date).to be_kind_of(Date) if process.termination_date
end
it 'has a status struct member with the expected data type' do
expect(process).to respond_to(:status)
expect(process.status).to be_nil # Always nil according to MSDN
end
it 'has a session_id struct member with the expected data type' do
expect(process).to respond_to(:session_id)
expect(process.session_id).to be_kind_of(Integer)
end
it 'has a read_transfer_count struct member with the expected data type' do
expect(process).to respond_to(:read_transfer_count)
expect(process.read_transfer_count).to be_kind_of(Integer)
end
it 'has a read_operation_count struct member with the expected data type' do
expect(process).to respond_to(:read_operation_count)
expect(process.read_operation_count).to be_kind_of(Integer)
end
it 'has a quota_peak_paged_pool_usage struct member with the expected data type' do
expect(process).to respond_to(:quota_peak_paged_pool_usage)
expect(process.quota_peak_paged_pool_usage).to be_kind_of(Integer)
end
it 'has a quota_peak_non_paged_pool_usage struct member with the expected data type' do
expect(process).to respond_to(:quota_peak_non_paged_pool_usage)
expect(process.quota_peak_non_paged_pool_usage).to be_kind_of(Integer)
end
it 'has a quota_paged_pool_usage struct member with the expected data type' do
expect(process).to respond_to(:quota_paged_pool_usage)
expect(process.quota_paged_pool_usage).to be_kind_of(Integer)
end
it 'has a quota_non_paged_pool_usage struct member with the expected data type' do
expect(process).to respond_to(:quota_non_paged_pool_usage)
expect(process.quota_non_paged_pool_usage).to be_kind_of(Integer)
end
it 'has a pid struct member with the expected data type' do
expect(process).to respond_to(:pid)
expect(process.pid).to be_kind_of(Integer)
end
it 'has a private_page_count struct member with the expected data type' do
expect(process).to respond_to(:private_page_count)
expect(process.private_page_count).to be_kind_of(Integer)
end
it 'has a priority struct member with the expected data type' do
expect(process).to respond_to(:priority)
expect(process.priority).to be_kind_of(Integer)
end
it 'has a peak_working_set_size struct member with the expected data type' do
expect(process).to respond_to(:peak_working_set_size)
expect(process.peak_working_set_size).to be_kind_of(Integer)
end
it 'has a peak_virtual_size struct member with the expected data type' do
expect(process).to respond_to(:peak_virtual_size)
expect(process.peak_virtual_size).to be_kind_of(Integer)
end
it 'has a peak_page_file_usage struct member with the expected data type' do
expect(process).to respond_to(:peak_page_file_usage)
expect(process.peak_page_file_usage).to be_kind_of(Integer)
end
it 'has a ppid struct member with the expected data type' do
expect(process).to respond_to(:ppid)
expect(process.ppid).to be_kind_of(Integer)
end
it 'has a page_file_usage struct member with the expected data type' do
expect(process).to respond_to(:page_file_usage)
expect(process.page_file_usage).to be_kind_of(Integer)
end
it 'has a page_faults struct member with the expected data type' do
expect(process).to respond_to(:page_faults)
expect(process.page_faults).to be_kind_of(Integer)
end
it 'has a other_transfer_count struct member with the expected data type' do
expect(process).to respond_to(:other_transfer_count)
expect(process.other_transfer_count).to be_kind_of(Integer)
end
it 'has a other_operation_count struct member with the expected data type' do
expect(process).to respond_to(:other_operation_count)
expect(process.other_operation_count).to be_kind_of(Integer)
end
it 'has a os_name struct member with the expected data type' do
expect(process).to respond_to(:os_name)
expect(process.os_name).to be_kind_of(String)
end
it 'has a os_creation_class_name struct member with the expected data type' do
expect(process).to respond_to(:os_creation_class_name)
expect(process.os_creation_class_name).to be_kind_of(String)
end
it 'has a name struct member with the expected data type' do
expect(process).to respond_to(:name)
expect(process.name).to be_kind_of(String)
end
it 'has a minimum_working_set_size struct member with the expected data type' do
expect(process).to respond_to(:minimum_working_set_size)
expect(process.minimum_working_set_size).to be_kind_of(Integer) if process.minimum_working_set_size
end
it 'has a maximum_working_set_size struct member with the expected data type' do
expect(process).to respond_to(:maximum_working_set_size)
expect(process.maximum_working_set_size).to be_kind_of(Integer) if process.maximum_working_set_size
end
it 'has a kernel_mode_time struct member with the expected data type' do
expect(process).to respond_to(:kernel_mode_time)
expect(process.kernel_mode_time).to be_kind_of(Integer)
end
it 'has a install_date struct member with the expected data type' do
expect(process).to respond_to(:install_date)
expect(process.install_date).to be_kind_of(Date) if process.install_date
end
it 'has a handle_count struct member with the expected data type' do
expect(process).to respond_to(:handle_count)
expect(process.handle_count).to be_kind_of(Integer)
end
it 'has a handle struct member with the expected data type' do
expect(process).to respond_to(:handle)
expect(process.handle).to be_kind_of(String)
end
it 'has a execution_state struct member with the expected data type' do
expect(process).to respond_to(:execution_state)
expect(process.execution_state).to be_nil
end
it 'has a executable_path struct member with the expected data type' do
expect(process).to respond_to(:executable_path)
expect(process.executable_path).to be_kind_of(String) if process.executable_path
end
it 'has a description struct member with the expected data type' do
expect(process).to respond_to(:description)
expect(process.description).to be_kind_of(String)
end
it 'has a cs_name struct member with the expected data type' do
expect(process).to respond_to(:cs_name)
expect(process.cs_name).to be_kind_of(String)
end
it 'has a cs_creation_class_name struct member with the expected data type' do
expect(process).to respond_to(:cs_creation_class_name)
expect(process.cs_creation_class_name).to be_kind_of(String)
end
it 'has a creation_date struct member with the expected data type' do
expect(process).to respond_to(:creation_date)
expect(process.creation_date).to be_kind_of(Date) if process.creation_date
end
it 'has a creation_class_name struct member with the expected data type' do
expect(process).to respond_to(:creation_class_name)
expect(process.creation_class_name).to be_kind_of(String)
end
it 'has a comm struct member with the expected data type' do
expect(process).to respond_to(:comm)
expect(process.comm).to be_kind_of(String)
end
it 'has a cmdline struct member with the expected data type' do
expect(process).to respond_to(:cmdline)
expect(process.cmdline).to be_kind_of(String) if process.cmdline
end
it 'has a caption struct member with the expected data type' do
expect(process).to respond_to(:caption)
expect(process.caption).to be_kind_of(String)
end
end
end
|