1
// Copyright 2015 CoreOS, Inc.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
21
func TestAllMatch(t *testing.T) {
34
// simple match of a single option
37
{Section: "Unit", Name: "Description", Value: "FOO"},
40
{Section: "Unit", Name: "Description", Value: "FOO"},
45
// single option mismatched
48
{Section: "Unit", Name: "Description", Value: "FOO"},
51
{Section: "Unit", Name: "Description", Value: "BAR"},
56
// multiple options match
59
{Section: "Unit", Name: "Description", Value: "FOO"},
60
{Section: "Unit", Name: "BindsTo", Value: "bar.service"},
61
{Section: "Service", Name: "ExecStart", Value: "/bin/true"},
64
{Section: "Unit", Name: "Description", Value: "FOO"},
65
{Section: "Unit", Name: "BindsTo", Value: "bar.service"},
66
{Section: "Service", Name: "ExecStart", Value: "/bin/true"},
74
{Section: "Unit", Name: "Description", Value: "FOO"},
75
{Section: "Unit", Name: "BindsTo", Value: "bar.service"},
78
{Section: "Unit", Name: "Description", Value: "FOO"},
79
{Section: "Unit", Name: "BindsTo", Value: "bar.service"},
80
{Section: "Service", Name: "ExecStart", Value: "/bin/true"},
85
// multiple options misordered
88
{Section: "Unit", Name: "Description", Value: "FOO"},
89
{Section: "Service", Name: "ExecStart", Value: "/bin/true"},
92
{Section: "Service", Name: "ExecStart", Value: "/bin/true"},
93
{Section: "Unit", Name: "Description", Value: "FOO"},
98
// interleaved sections mismatch
101
{Section: "Unit", Name: "Description", Value: "FOO"},
102
{Section: "Unit", Name: "BindsTo", Value: "bar.service"},
103
{Section: "Service", Name: "ExecStart", Value: "/bin/true"},
104
{Section: "Service", Name: "ExecStop", Value: "/bin/true"},
107
{Section: "Unit", Name: "Description", Value: "FOO"},
108
{Section: "Service", Name: "ExecStart", Value: "/bin/true"},
109
{Section: "Unit", Name: "BindsTo", Value: "bar.service"},
110
{Section: "Service", Name: "ExecStop", Value: "/bin/true"},
116
for i, tt := range tests {
117
match := AllMatch(tt.u1, tt.u2)
118
if match != tt.match {
119
t.Errorf("case %d: failed comparing u1 to u2 - expected match=%t, got %t", i, tt.match, match)
122
match = AllMatch(tt.u2, tt.u1)
123
if match != tt.match {
124
t.Errorf("case %d: failed comparing u2 to u1 - expected match=%t, got %t", i, tt.match, match)
129
func TestMatch(t *testing.T) {
135
// empty options match
203
for i, tt := range tests {
204
match := tt.o1.Match(tt.o2)
205
if match != tt.match {
206
t.Errorf("case %d: failed comparing o1 to o2 - expected match=%t, got %t", i, tt.match, match)
209
match = tt.o2.Match(tt.o1)
210
if match != tt.match {
211
t.Errorf("case %d: failed comparing o2 to o1 - expected match=%t, got %t", i, tt.match, match)