blob: 16ec72cb569d21cc3220ceda0b2b0cc84df219f0 [file] [log] [blame]
Bob Badoura99ac622021-10-25 16:21:00 -07001// Copyright 2021 Google LLC
2//
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
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
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.
14
15package compliance
16
17import (
Bob Badoura99ac622021-10-25 16:21:00 -070018 "testing"
19)
20
Bob Badour103eb0f2022-01-10 13:50:57 -080021func TestConditionSetHas(t *testing.T) {
22 impliesShare := ImpliesShared
Bob Badoura99ac622021-10-25 16:21:00 -070023
Bob Badour10f5c482022-09-20 21:44:17 -070024 t.Logf("testing with imliesShare=%#v", impliesShare)
Bob Badour103eb0f2022-01-10 13:50:57 -080025
26 if impliesShare.HasAny(NoticeCondition) {
Bob Badour10f5c482022-09-20 21:44:17 -070027 t.Errorf("impliesShare.HasAny(\"notice\"=%#v) got true, want false", NoticeCondition)
Bob Badoura99ac622021-10-25 16:21:00 -070028 }
29
Bob Badour103eb0f2022-01-10 13:50:57 -080030 if !impliesShare.HasAny(RestrictedCondition) {
Bob Badour10f5c482022-09-20 21:44:17 -070031 t.Errorf("impliesShare.HasAny(\"restricted\"=%#v) got false, want true", RestrictedCondition)
Bob Badoura99ac622021-10-25 16:21:00 -070032 }
33
Bob Badour103eb0f2022-01-10 13:50:57 -080034 if !impliesShare.HasAny(ReciprocalCondition) {
Bob Badour10f5c482022-09-20 21:44:17 -070035 t.Errorf("impliesShare.HasAny(\"reciprocal\"=%#v) got false, want true", ReciprocalCondition)
Bob Badoura99ac622021-10-25 16:21:00 -070036 }
37
Bob Badour103eb0f2022-01-10 13:50:57 -080038 if impliesShare.HasAny(LicenseCondition(0x0000)) {
Bob Badour10f5c482022-09-20 21:44:17 -070039 t.Errorf("impliesShare.HasAny(nil=%#v) got true, want false", LicenseCondition(0x0000))
Bob Badoura99ac622021-10-25 16:21:00 -070040 }
41}
42
Bob Badour103eb0f2022-01-10 13:50:57 -080043func TestConditionName(t *testing.T) {
44 for expected, condition := range RecognizedConditionNames {
45 actual := condition.Name()
46 if expected != actual {
Bob Badour10f5c482022-09-20 21:44:17 -070047 t.Errorf("unexpected name for condition %#v: got %s, want %s", condition, actual, expected)
Bob Badour103eb0f2022-01-10 13:50:57 -080048 }
Bob Badoura99ac622021-10-25 16:21:00 -070049 }
Bob Badour103eb0f2022-01-10 13:50:57 -080050}
51
52func TestConditionName_InvalidCondition(t *testing.T) {
53 panicked := false
54 var lc LicenseCondition
55 func() {
56 defer func() {
57 if err := recover(); err != nil {
58 panicked = true
Bob Badoura99ac622021-10-25 16:21:00 -070059 }
Bob Badour103eb0f2022-01-10 13:50:57 -080060 }()
61 name := lc.Name()
62 t.Errorf("invalid condition unexpected name: got %s, wanted panic", name)
63 }()
64 if !panicked {
Bob Badour10f5c482022-09-20 21:44:17 -070065 t.Errorf("no expected panic for %#v.Name(): got no panic, wanted panic", lc)
Bob Badoura99ac622021-10-25 16:21:00 -070066 }
67}