5 require File.dirname(__FILE__) + "/../../../../../plugins/mcollective/data/fstat_data.rb"
10 describe "#query_data" do
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
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)
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"
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")
48 @stat.stubs(:file?).returns(true)
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"
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)
74 @stat.stubs(:symlink?).returns(true)
76 @plugin.query_data("rspec")
77 @plugin.result.output.should == "present"
78 @plugin.result.md5.should == 0
79 @plugin.result.type.should == "symlink"
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)
87 @stat.stubs(:directory?).returns(true)
89 @plugin.query_data("rspec")
90 @plugin.result.output.should == "present"
91 @plugin.result.md5.should == 0
92 @plugin.result.type.should == "directory"
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)
100 @stat.stubs(:socket?).returns(true)
102 @plugin.query_data("rspec")
103 @plugin.result.output.should == "present"
104 @plugin.result.md5.should == 0
105 @plugin.result.type.should == "socket"
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)
113 @stat.stubs(:chardev?).returns(true)
115 @plugin.query_data("rspec")
116 @plugin.result.output.should == "present"
117 @plugin.result.md5.should == 0
118 @plugin.result.type.should == "chardev"
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)
126 @stat.stubs(:blockdev?).returns(true)
128 @plugin.query_data("rspec")
129 @plugin.result.output.should == "present"
130 @plugin.result.md5.should == 0
131 @plugin.result.type.should == "blockdev"