github.com/go-maxhub/gremlins@v1.0.1-0.20231227222204-b03a6a1e3e09/core/configuration/mutantenables_test.go (about) 1 /* 2 * Copyright 2022 The Gremlins Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package configuration_test 18 19 import ( 20 "testing" 21 22 "github.com/go-maxhub/gremlins/core/configuration" 23 "github.com/go-maxhub/gremlins/core/mutator" 24 ) 25 26 func TestMutantDefaultStatus(t *testing.T) { 27 t.Parallel() 28 type testCase struct { 29 mutantType mutator.Type 30 expected bool 31 } 32 testCases := []testCase{ 33 { 34 mutantType: mutator.ArithmeticBase, 35 expected: true, 36 }, 37 { 38 mutantType: mutator.ConditionalsBoundary, 39 expected: true, 40 }, 41 { 42 mutantType: mutator.ConditionalsNegation, 43 expected: true, 44 }, 45 { 46 mutantType: mutator.IncrementDecrement, 47 expected: true, 48 }, 49 { 50 mutantType: mutator.InvertBitwise, 51 expected: false, 52 }, 53 { 54 mutantType: mutator.InvertBitwiseAssignments, 55 expected: false, 56 }, 57 { 58 mutantType: mutator.InvertLogical, 59 expected: false, 60 }, 61 { 62 mutantType: mutator.InvertNegatives, 63 expected: true, 64 }, 65 { 66 mutantType: mutator.InvertLoopCtrl, 67 expected: false, 68 }, 69 { 70 mutantType: mutator.InvertAssignments, 71 expected: false, 72 }, 73 { 74 mutantType: mutator.RemoveSelfAssignments, 75 expected: false, 76 }, 77 } 78 79 for _, tc := range testCases { 80 tc := tc 81 t.Run(tc.mutantType.String(), func(t *testing.T) { 82 t.Parallel() 83 got := configuration.IsDefaultEnabled(tc.mutantType) 84 85 if got != tc.expected { 86 t.Errorf("expected %s to be %q, got %q", tc.mutantType, enabled(tc.expected), enabled(got)) 87 } 88 }) 89 } 90 91 // This should prevent the behaviour described in #142 92 t.Run("all MutantTypes are testes for default", func(t *testing.T) { 93 contains := func(testedMT []testCase, mt mutator.Type) bool { 94 for _, c := range testedMT { 95 if mt == c.mutantType { 96 return true 97 } 98 } 99 100 return false 101 } 102 103 for _, mt := range mutator.Types { 104 if contains(testCases, mt) { 105 continue 106 } 107 108 t.Errorf("MutantTypes contains %q which is not tested for default", mt) 109 } 110 }) 111 } 112 113 func enabled(b bool) string { 114 if b { 115 return "enabled" 116 } 117 118 return "disabled" 119 }