228c0b1b78a63e6c6ec5fee29e92c5fc3339e845
[packages/precise/mcollective.git] / spec / unit / plugins / mcollective / data / fstat_data_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 require File.dirname(__FILE__) + "/../../../../../plugins/mcollective/data/fstat_data.rb"
6
7 module MCollective
8   module Data
9     describe Fstat_data do
10       describe "#query_data" do
11         before do
12           @ddl = mock
13           @ddl.stubs(:meta).returns({:timeout => 1})
14           @ddl.stubs(:dataquery_interface).returns({:output => {}})
15           DDL.stubs(:new).returns(@ddl)
16           @plugin = Fstat_data.new
17
18           @time = Time.now
19
20           @stat = mock
21           @stat.stubs(:size).returns(123)
22           @stat.stubs(:uid).returns(0)
23           @stat.stubs(:gid).returns(0)
24           @stat.stubs(:mtime).returns(@time)
25           @stat.stubs(:ctime).returns(@time)
26           @stat.stubs(:atime).returns(@time)
27           @stat.stubs(:mode).returns(33188)
28           @stat.stubs(:directory?).returns(false)
29           @stat.stubs(:file?).returns(false)
30           @stat.stubs(:symlink?).returns(false)
31           @stat.stubs(:socket?).returns(false)
32           @stat.stubs(:chardev?).returns(false)
33           @stat.stubs(:blockdev?).returns(false)
34         end
35
36         it "should detect missing files" do
37           File.expects(:exists?).with("/nonexisting").returns(false)
38           @plugin.query_data("/nonexisting")
39           @plugin.result.output.should == "not present"
40         end
41
42         it "should provide correct file stats" do
43           File.expects(:exists?).with("rspec").returns(true)
44           File.expects(:symlink?).with("rspec").returns(false)
45           File.expects(:stat).with("rspec").returns(@stat)
46           File.expects(:read).with("rspec").returns("rspec")
47
48           @stat.stubs(:file?).returns(true)
49
50           @plugin.query_data("rspec")
51           @plugin.result.output.should == "present"
52           @plugin.result.size.should == 123
53           @plugin.result.uid.should == 0
54           @plugin.result.gid.should == 0
55           @plugin.result.mtime.should == @time.strftime("%F %T")
56           @plugin.result.mtime_seconds.should == @time.to_i
57           @plugin.result.mtime_age.should <= 5
58           @plugin.result.ctime.should == @time.strftime("%F %T")
59           @plugin.result.ctime_seconds.should == @time.to_i
60           @plugin.result.ctime_age.should <= 5
61           @plugin.result.atime.should == @time.strftime("%F %T")
62           @plugin.result.atime_seconds.should == @time.to_i
63           @plugin.result.atime_age.should <= 5
64           @plugin.result.mode.should == "100644"
65           @plugin.result.md5.should == "2bc84dc69b73db9383b9c6711d2011b7"
66           @plugin.result.type.should == "file"
67         end
68
69         it "should provide correct link stats" do
70           File.expects(:exists?).with("rspec").returns(true)
71           File.expects(:symlink?).with("rspec").returns(true)
72           File.expects(:lstat).with("rspec").returns(@stat)
73
74           @stat.stubs(:symlink?).returns(true)
75
76           @plugin.query_data("rspec")
77           @plugin.result.output.should == "present"
78           @plugin.result.md5.should == 0
79           @plugin.result.type.should == "symlink"
80         end
81
82         it "should provide correct directory stats" do
83           File.expects(:exists?).with("rspec").returns(true)
84           File.expects(:symlink?).with("rspec").returns(false)
85           File.expects(:stat).with("rspec").returns(@stat)
86
87           @stat.stubs(:directory?).returns(true)
88
89           @plugin.query_data("rspec")
90           @plugin.result.output.should == "present"
91           @plugin.result.md5.should == 0
92           @plugin.result.type.should == "directory"
93         end
94
95         it "should provide correct socket stats" do
96           File.expects(:exists?).with("rspec").returns(true)
97           File.expects(:symlink?).with("rspec").returns(false)
98           File.expects(:stat).with("rspec").returns(@stat)
99
100           @stat.stubs(:socket?).returns(true)
101
102           @plugin.query_data("rspec")
103           @plugin.result.output.should == "present"
104           @plugin.result.md5.should == 0
105           @plugin.result.type.should == "socket"
106         end
107
108         it "should provide correct chardev stats" do
109           File.expects(:exists?).with("rspec").returns(true)
110           File.expects(:symlink?).with("rspec").returns(false)
111           File.expects(:stat).with("rspec").returns(@stat)
112
113           @stat.stubs(:chardev?).returns(true)
114
115           @plugin.query_data("rspec")
116           @plugin.result.output.should == "present"
117           @plugin.result.md5.should == 0
118           @plugin.result.type.should == "chardev"
119         end
120
121         it "should provide correct blockdev stats" do
122           File.expects(:exists?).with("rspec").returns(true)
123           File.expects(:symlink?).with("rspec").returns(false)
124           File.expects(:stat).with("rspec").returns(@stat)
125
126           @stat.stubs(:blockdev?).returns(true)
127
128           @plugin.query_data("rspec")
129           @plugin.result.output.should == "present"
130           @plugin.result.md5.should == 0
131           @plugin.result.type.should == "blockdev"
132         end
133       end
134     end
135   end
136 end