Permalink
Browse files

r1396@vesla: ilmari | 2006-05-29 14:07:30 +0100

 Add testing framework and some tests for munin-run.
  • Loading branch information...
1 parent 7cc8d65 commit e949d1595d83d2880edad49867aa0f61e9b2f9b5 @ilmari ilmari committed May 29, 2006
Showing with 201 additions and 1 deletion.
  1. +24 −1 Makefile
  2. +42 −0 node/node.d/env.in
  3. +38 −0 node/node.d/id.in
  4. +38 −0 t/Makefile.config
  5. +53 −0 t/munin-run.t
  6. +3 −0 t/plugin-conf.d/env
  7. +3 −0 t/plugin-conf.d/id
View
25 Makefile
@@ -248,11 +248,34 @@ endif
-rm -f build-stamp
-rm -f build-doc-stamp
-rm -f build-man-stamp
+ -rm -rf t/install
-rm -f dists/redhat/munin.spec
source_dist: clean
(cd ..; ln -s $(DIR) munin-$(VERSION))
tar -C .. --dereference --exclude .svn -cvzf ../munin_$(RELEASE).tar.gz munin-$(VERSION)/
-.PHONY: install install-main install-node install-doc install-man build build-doc deb clean source_dist
+ifeq ($(MAKELEVEL),0)
+# Re-exec make with the test config
+test: t/*.t
+ $(MAKE) $@ CONFIG=t/Makefile.config
+else
+test_plugins = id_default id_root env
+test: t/*.t t/install $(addprefix $(CONFDIR)/plugins/,$(test_plugins))
+ @for test in t/*.t; do \
+ echo -n "$$test: "; \
+ PERL5LIB=$(PERLLIB) $(PERL) $$test;\
+ done
+endif
+
+$(CONFDIR)/plugins/id_%: $(LIBDIR)/plugins/id
+ ln -s $< $@
+
+$(CONFDIR)/plugins/%: $(LIBDIR)/plugins/%
+ ln -s $< $@
+
+t/install:
+ $(MAKE) clean install-node install-node-plugins CONFIG=t/Makefile.config INSTALL_PLUGINS=test
+
+.PHONY: install install-main install-node install-doc install-man build build-doc deb clean source_dist test
View
42 node/node.d/env.in
@@ -0,0 +1,42 @@
+#!@@PERL@@ -w
+# -*- perl -*-
+#
+# Copyright (C) 2004 Dagfinn Ilmari Mannsaaker
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 dated June, 1991.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+#
+# Plugin for testing enviroment setting.
+#
+#%# family=test
+use strict;
+
+my @keys = grep /^munin/, keys %ENV;
+
+if ($ARGV[0] and $ARGV[0] eq 'config') {
+ print "graph_title Environment variables\n";
+ print "graph no\n";
+ print "count.label count\n";
+ for my $key (@keys) {
+ print "$key.label $key length\n";
+ }
+ exit 0;
+}
+
+print "count.value ", scalar(@keys), "\n";
+
+for my $key (@keys) {
+ print "$key.value ", length($ENV{$key}), "\n";
+ print "$key.extinfo $ENV{$key}\n";
+}
View
38 node/node.d/id.in
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# Copyright (C) 2006 Dagfinn Ilmari Mannsaaker <ilmari@ilmari.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 dated June, 1991.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+#
+# Plugin for testing user and group statements in the plugin config.
+#
+#%# family=test
+
+if [ "$1" = "config" ]; then
+ echo "graph_title User and groups"
+ echo "graph no"
+ echo "uid.label User ID"
+ echo "gid.label Group ID"
+ exit 0
+fi
+
+echo -n "uid.value "
+id -u
+echo -n "uid.extinfo "
+id -nu
+echo -n "gid.value "
+id -g
+echo -n "gid.extinfo "
+id -Gn
View
38 t/Makefile.config
@@ -0,0 +1,38 @@
+# Bulid config for testing
+
+# DESTDIR is empty during building, and optionally set to point to
+# a shadow tree during make install.
+
+#
+# the base of the Munin installation.
+#
+PREFIX = $(PWD)/t/install
+
+# Where Munin keeps its configurations (server.conf, client.conf, ++)
+CONFDIR = $(PREFIX)/etc
+
+# Client only - Where to put RRD files and other intenal data
+DBDIR = $(PREFIX)/var/lib
+
+# Where Munin should place its logs.
+LOGDIR = $(PREFIX)/var/log
+
+# Location of PID files and other statefiles. On the server, must be
+# writable by the user "munin".
+STATEDIR = $(PREFIX)/var/run
+
+# Server only - Where to install the perl libraries
+PERLLIB = $(PREFIX)/perl
+
+# User to run munin as
+USER = nobody
+GROUP = nogroup
+
+# Default user to run the plugins as
+PLUGINUSER = nobody
+
+CHECKUSER = \#
+CHECKGROUP = \#
+CHOWN = \#
+CHMOD = \#
+CHGRP = \#
View
53 t/munin-run.t
@@ -0,0 +1,53 @@
+use Test::More tests => 6;
+use strict;
+
+my $PREFIX = $ENV{PWD}.'/t/install';
+my $run = "$PREFIX/sbin/munin-run --sconfdir=$ENV{PWD}/t/plugin-conf.d";
+
+sub run {
+ my $plugin = shift or die "run(): plugin required\n";
+
+ my @lines = `$run $plugin` or warn "No output from '$plugin' plugin\n";
+ warn "Error running '$plugin' plugin\n", @lines if $?;
+
+ my %ret;
+ for (@lines) {
+ if (/^(\w+)\.(\w+)\s+(.+)/) { # unfuck cperl-mode +
+ $ret{$1}{$2} = $3;
+ }
+ elsif (/(\w+)\s+(.+)/) {
+ $ret{$1} = $2;
+ }
+ }
+ return %ret;
+}
+
+SKIP: {
+ skip "need root for uid/gid tests", 4 if $>;
+ skip "nobody/nogroup missing", 4
+ unless getpwnam('nobody') && getgrnam('nogroup');
+
+ my %id = run('id_default');
+ is($id{uid}{extinfo}, 'nobody', "default user");
+ like($id{gid}{extinfo}, qr/^nogroup/, "default group");
+
+ my %id = run('id_root');
+ is($id{uid}{value}, 0, 'user override');
+ like($id{gid}{extinfo}, qr/\broot\b/, 'group override');
+}
+
+my %env = run('env');
+is_deeply(\%env,
+ { count => { value => 1 },
+ munin_test => { value => 4,
+ extinfo => 'test',
+ },
+ },
+ 'environment variables');
+
+TODO: {
+ local $TODO = "munin-run doesn't handle this";
+
+ my %config = run('env config');
+ is($config{host_name}, 'test.example.com', 'host_name override');
+}
View
3 t/plugin-conf.d/env
@@ -0,0 +1,3 @@
+[env]
+host_name test.example.com
+env.munin_test test
View
3 t/plugin-conf.d/id
@@ -0,0 +1,3 @@
+[id_root]
+user root
+group root

0 comments on commit e949d15

Please sign in to comment.