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(:new).returns(@ddl)
15 @plugin = Fstat_data.new
20 @stat.stubs(:size).returns(123)
21 @stat.stubs(:uid).returns(0)
22 @stat.stubs(:gid).returns(0)
23 @stat.stubs(:mtime).returns(@time)
24 @stat.stubs(:ctime).returns(@time)
25 @stat.stubs(:atime).returns(@time)
26 @stat.stubs(:mode).returns(33188)
27 @stat.stubs(:directory?).returns(false)
28 @stat.stubs(:file?).returns(false)
29 @stat.stubs(:symlink?).returns(false)
30 @stat.stubs(:socket?).returns(false)
31 @stat.stubs(:chardev?).returns(false)
32 @stat.stubs(:blockdev?).returns(false)
35 it "should detect missing files" do
36 File.expects(:exists?).with("/nonexisting").returns(false)
37 @plugin.query_data("/nonexisting")
38 @plugin.result.output.should == "not present"
41 it "should provide correct file stats" do
42 File.expects(:exists?).with("rspec").returns(true)
43 File.expects(:symlink?).with("rspec").returns(false)
44 File.expects(:stat).with("rspec").returns(@stat)
45 File.expects(:read).with("rspec").returns("rspec")
47 @stat.stubs(:file?).returns(true)
49 @plugin.query_data("rspec")
50 @plugin.result.output.should == "present"
51 @plugin.result.size.should == 123
52 @plugin.result.uid.should == 0
53 @plugin.result.gid.should == 0
54 @plugin.result.mtime.should == @time.strftime("%F %T")
55 @plugin.result.mtime_seconds.should == @time.to_i
56 @plugin.result.mtime_age.should <= 5
57 @plugin.result.ctime.should == @time.strftime("%F %T")
58 @plugin.result.ctime_seconds.should == @time.to_i
59 @plugin.result.ctime_age.should <= 5
60 @plugin.result.atime.should == @time.strftime("%F %T")
61 @plugin.result.atime_seconds.should == @time.to_i
62 @plugin.result.atime_age.should <= 5
63 @plugin.result.mode.should == "100644"
64 @plugin.result.md5.should == "2bc84dc69b73db9383b9c6711d2011b7"
65 @plugin.result.type.should == "file"
68 it "should provide correct link stats" do
69 File.expects(:exists?).with("rspec").returns(true)
70 File.expects(:symlink?).with("rspec").returns(true)
71 File.expects(:lstat).with("rspec").returns(@stat)
73 @stat.stubs(:symlink?).returns(true)
75 @plugin.query_data("rspec")
76 @plugin.result.output.should == "present"
77 @plugin.result.md5.should == 0
78 @plugin.result.type.should == "symlink"
81 it "should provide correct directory stats" do
82 File.expects(:exists?).with("rspec").returns(true)
83 File.expects(:symlink?).with("rspec").returns(false)
84 File.expects(:stat).with("rspec").returns(@stat)
86 @stat.stubs(:directory?).returns(true)
88 @plugin.query_data("rspec")
89 @plugin.result.output.should == "present"
90 @plugin.result.md5.should == 0
91 @plugin.result.type.should == "directory"
94 it "should provide correct socket stats" do
95 File.expects(:exists?).with("rspec").returns(true)
96 File.expects(:symlink?).with("rspec").returns(false)
97 File.expects(:stat).with("rspec").returns(@stat)
99 @stat.stubs(:socket?).returns(true)
101 @plugin.query_data("rspec")
102 @plugin.result.output.should == "present"
103 @plugin.result.md5.should == 0
104 @plugin.result.type.should == "socket"
107 it "should provide correct chardev stats" do
108 File.expects(:exists?).with("rspec").returns(true)
109 File.expects(:symlink?).with("rspec").returns(false)
110 File.expects(:stat).with("rspec").returns(@stat)
112 @stat.stubs(:chardev?).returns(true)
114 @plugin.query_data("rspec")
115 @plugin.result.output.should == "present"
116 @plugin.result.md5.should == 0
117 @plugin.result.type.should == "chardev"
120 it "should provide correct blockdev stats" do
121 File.expects(:exists?).with("rspec").returns(true)
122 File.expects(:symlink?).with("rspec").returns(false)
123 File.expects(:stat).with("rspec").returns(@stat)
125 @stat.stubs(:blockdev?).returns(true)
127 @plugin.query_data("rspec")
128 @plugin.result.output.should == "present"
129 @plugin.result.md5.should == 0
130 @plugin.result.type.should == "blockdev"