github.com/network-quality/goresponsiveness@v0.0.0-20240129151524-343954285090/rpm/parameters_test.go (about) 1 /* 2 * This file is part of Go Responsiveness. 3 * 4 * Go Responsiveness is free software: you can redistribute it and/or modify it under 5 * the terms of the GNU General Public License as published by the Free Software Foundation, 6 * either version 2 of the License, or (at your option) any later version. 7 * Go Responsiveness is distributed in the hope that it will be useful, but WITHOUT ANY 8 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 9 * PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along 12 * with Go Responsiveness. If not, see <https://www.gnu.org/licenses/>. 13 */ 14 15 package rpm 16 17 import ( 18 "strings" 19 "testing" 20 21 "github.com/network-quality/goresponsiveness/executor" 22 ) 23 24 func TestSpecParametersFromArgumentsBadTimeout(t *testing.T) { 25 _, err := SpecParametersFromArguments(0, 0, 0, 0, 0, 0, 0, 0, 0, executor.Parallel) 26 if err == nil || !strings.Contains(err.Error(), "timeout") { 27 t.Fatalf("0 timeout improperly allowed.") 28 } 29 _, err = SpecParametersFromArguments(-1, 0, 0, 0, 0, 0, 0, 0, 0, executor.Parallel) 30 if err == nil || !strings.Contains(err.Error(), "timeout") { 31 t.Fatalf("negative timeout improperly allowed.") 32 } 33 } 34 35 func TestSpecParametersFromArgumentsBadMad(t *testing.T) { 36 _, err := SpecParametersFromArguments(1, 0, 0, 0, 0, 0, 0, 0, 0, executor.Parallel) 37 if err == nil || !strings.Contains(err.Error(), "moving-average") { 38 t.Fatalf("0 mad improperly allowed.") 39 } 40 _, err = SpecParametersFromArguments(1, 0, 0, 0, 0, 0, 0, 0, 0, executor.Parallel) 41 if err == nil || !strings.Contains(err.Error(), "moving-average") { 42 t.Fatalf("negative mad improperly allowed.") 43 } 44 } 45 46 func TestSpecParametersFromArgumentsBadId(t *testing.T) { 47 _, err := SpecParametersFromArguments(1, 1, 0, 0, 0, 0, 0, 0, 0, executor.Parallel) 48 if err == nil || !strings.Contains(err.Error(), "reevaluation") { 49 t.Fatalf("0 id improperly allowed.") 50 } 51 _, err = SpecParametersFromArguments(1, 1, -1, 0, 0, 0, 0, 0, 0, executor.Parallel) 52 if err == nil || !strings.Contains(err.Error(), "reevaluation") { 53 t.Fatalf("negative id improperly allowed.") 54 } 55 } 56 57 func TestSpecParametersFromArgumentsBadSdt(t *testing.T) { 58 _, err := SpecParametersFromArguments(1, 1, 1, 1, -1, 0, 0, 0, 0, executor.Parallel) 59 if err == nil || !strings.Contains(err.Error(), "deviation") { 60 t.Fatalf("0 sdt improperly allowed.") 61 } 62 } 63 64 func TestSpecParametersFromArgumentsBadMnp(t *testing.T) { 65 _, err := SpecParametersFromArguments(1, 1, 1, 1, 1, 0, 0, 0, 0, executor.Parallel) 66 if err == nil || !strings.Contains(err.Error(), "parallel") { 67 t.Fatalf("0 mnp improperly allowed.") 68 } 69 _, err = SpecParametersFromArguments(1, 1, 1, 1, 1, -1, 0, 0, 0, executor.Parallel) 70 if err == nil || !strings.Contains(err.Error(), "parallel") { 71 t.Fatalf("negative mnp improperly allowed.") 72 } 73 } 74 75 func TestSpecParametersFromArgumentsBadMps(t *testing.T) { 76 _, err := SpecParametersFromArguments(1, 1, 1, 1, 1, 1, 0, 0, 0, executor.Parallel) 77 if err == nil || !strings.Contains(err.Error(), "probing interval") { 78 t.Fatalf("0 mps improperly allowed.") 79 } 80 _, err = SpecParametersFromArguments(1, 1, 1, 1, 1, 1, -1, 0, 0, executor.Parallel) 81 if err == nil || !strings.Contains(err.Error(), "probing interval") { 82 t.Fatalf("negative mps improperly allowed.") 83 } 84 } 85 86 func TestSpecParametersFromArgumentsBadPtc(t *testing.T) { 87 _, err := SpecParametersFromArguments(1, 1, 1, 1, 1, 1, 1, 0, 0, executor.Parallel) 88 if err == nil || !strings.Contains(err.Error(), "capacity") { 89 t.Fatalf("0 ptc improperly allowed.") 90 } 91 _, err = SpecParametersFromArguments(1, 1, 1, 1, 1, 1, 1, -1, 0, executor.Parallel) 92 if err == nil || !strings.Contains(err.Error(), "capacity") { 93 t.Fatalf("negative ptc improperly allowed.") 94 } 95 } 96 97 func TestSpecParametersFromArgumentsBadP(t *testing.T) { 98 _, err := SpecParametersFromArguments(1, 1, 1, 1, 1, 1, 1, 1, -1, executor.Parallel) 99 if err == nil || !strings.Contains(err.Error(), "percentile") { 100 t.Fatalf("-1 percentile improperly allowed.") 101 } 102 _, err = SpecParametersFromArguments(1, 1, 1, 1, 1, 1, 1, 1, 0, executor.Parallel) 103 if err == nil || !strings.Contains(err.Error(), "percentile") { 104 t.Fatalf("0 percentile improperly allowed.") 105 } 106 _, err = SpecParametersFromArguments(1, 1, 1, 1, 1, 1, 1, 1, 101, executor.Parallel) 107 if err == nil || !strings.Contains(err.Error(), "percentile") { 108 t.Fatalf("percentile greater than 100 improperly allowed.") 109 } 110 }