1// Copyright 2015 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// +build !windows,!nacl,!plan9
15
16package log
17
18import (
19	"errors"
20	"log/syslog"
21	"testing"
22)
23
24func TestGetFacility(t *testing.T) {
25	testCases := []struct {
26		facility         string
27		expectedPriority syslog.Priority
28		expectedErr      error
29	}{
30		{"0", syslog.LOG_LOCAL0, nil},
31		{"1", syslog.LOG_LOCAL1, nil},
32		{"2", syslog.LOG_LOCAL2, nil},
33		{"3", syslog.LOG_LOCAL3, nil},
34		{"4", syslog.LOG_LOCAL4, nil},
35		{"5", syslog.LOG_LOCAL5, nil},
36		{"6", syslog.LOG_LOCAL6, nil},
37		{"7", syslog.LOG_LOCAL7, nil},
38		{"8", syslog.LOG_LOCAL0, errors.New("invalid local(8) for syslog")},
39	}
40	for _, tc := range testCases {
41		priority, err := getFacility(tc.facility)
42		if err != tc.expectedErr {
43			if err.Error() != tc.expectedErr.Error() {
44				t.Errorf("want %s, got %s", tc.expectedErr.Error(), err.Error())
45			}
46		}
47
48		if priority != tc.expectedPriority {
49			t.Errorf("want %q, got %q", tc.expectedPriority, priority)
50		}
51	}
52}
53