From 457aec64dba91f975552785416b996a269f5e386 Mon Sep 17 00:00:00 2001 From: cn Date: Fri, 3 May 2013 21:38:10 +0200 Subject: [PATCH] Add some parser tests --- spec/parser/modern_stateless_spec.rb | 23 +++++++++++++++++++++++ spec/parser/v1_spec.rb | 18 ++++++++++++++++++ spec/spec_helper.rb | 21 +++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 spec/parser/modern_stateless_spec.rb create mode 100644 spec/parser/v1_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/spec/parser/modern_stateless_spec.rb b/spec/parser/modern_stateless_spec.rb new file mode 100644 index 0000000..de76b09 --- /dev/null +++ b/spec/parser/modern_stateless_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe OpenVPNStatusWeb::Parser::ModernStateless do + { + 2 => status_v2, + 3 => status_v3 + }.each do |version, status| + context "for status-version #{version}" do + it 'parses client list' do + status.client_list.map { |client| client[0] }.should be_eql ["foo", "bar"] + end + + it 'parses routing table' do + status.routing_table.map { |route| route[1] }.should be_eql ["foo", "bar", "foo", "bar"] + end + + it 'parses global stats' do + status.global_stats.size.should be_eql 1 + status.global_stats.first.should be_eql ["Max bcast/mcast queue length", "42"] + end + end + end +end diff --git a/spec/parser/v1_spec.rb b/spec/parser/v1_spec.rb new file mode 100644 index 0000000..6ca23a6 --- /dev/null +++ b/spec/parser/v1_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe OpenVPNStatusWeb::Parser::V1 do + def status; status_v1; end + + it 'parses client list' do + status.client_list.map { |client| client[0] }.should be_eql ["foo", "bar"] + end + + it 'parses routing table' do + status.routing_table.map { |route| route[1] }.should be_eql ["foo", "bar", "foo", "bar"] + end + + it 'parses global stats' do + status.global_stats.size.should be_eql 1 + status.global_stats.first.should be_eql ["Max bcast/mcast queue length", "42"] + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..4e66db5 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,21 @@ + +require 'rubygems' +require 'bundler/setup' +require 'rack/test' + +require 'openvpn-status-web' + +def status_v1 + text = File.open('examples/status.v1', 'rb') do |f| f.read end + OpenVPNStatusWeb::Parser::V1.new.parse_status_log text +end + +def status_v2 + text = File.open('examples/status.v2', 'rb') do |f| f.read end + OpenVPNStatusWeb::Parser::V2.new.parse_status_log text +end + +def status_v3 + text = File.open('examples/status.v3', 'rb') do |f| f.read end + OpenVPNStatusWeb::Parser::V3.new.parse_status_log text +end