babca399865e11b328c1eb8354e8ef50e65dac95
[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(:new).returns(@ddl)
15           @plugin = Fstat_data.new
16
17           @time = Time.now
18
19           @stat = mock
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)
33         end
34
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"
39         end
40
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")
46
47           @stat.stubs(:file?).returns(true)
48
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"
66         end
67
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)
72
73           @stat.stubs(:symlink?).returns(true)
74
75           @plugin.query_data("rspec")
76           @plugin.result.output.should == "present"
77           @plugin.result.md5.should == 0
78           @plugin.result.type.should == "symlink"
79         end
80
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)
85
86           @stat.stubs(:directory?).returns(true)
87
88           @plugin.query_data("rspec")
89           @plugin.result.output.should == "present"
90           @plugin.result.md5.should == 0
91           @plugin.result.type.should == "directory"
92         end
93
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)
98
99           @stat.stubs(:socket?).returns(true)
100
101           @plugin.query_data("rspec")
102           @plugin.result.output.should == "present"
103           @plugin.result.md5.should == 0
104           @plugin.result.type.should == "socket"
105         end
106
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)
111
112           @stat.stubs(:chardev?).returns(true)
113
114           @plugin.query_data("rspec")
115           @plugin.result.output.should == "present"
116           @plugin.result.md5.should == 0
117           @plugin.result.type.should == "chardev"
118         end
119
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)
124
125           @stat.stubs(:blockdev?).returns(true)
126
127           @plugin.query_data("rspec")
128           @plugin.result.output.should == "present"
129           @plugin.result.md5.should == 0
130           @plugin.result.type.should == "blockdev"
131         end
132       end
133     end
134   end
135 end