github.com/kubewharf/katalyst-core@v0.5.3/pkg/controller/resource-recommend/processor/percentile/process_util_test.go (about) 1 /* 2 Copyright 2022 The Katalyst 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 percentile 18 19 import ( 20 "reflect" 21 "testing" 22 23 "github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor/percentile/task" 24 processortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/processor" 25 ) 26 27 func TestProcessor_getTaskForProcessKey(t *testing.T) { 28 type newProcessor func() *Processor 29 tests := []struct { 30 name string 31 newProcessor newProcessor 32 processKey *processortypes.ProcessKey 33 want *task.HistogramTask 34 wantErr bool 35 }{ 36 { 37 name: "processConfig is nil", 38 processKey: nil, 39 want: nil, 40 wantErr: true, 41 }, 42 { 43 name: "processConfig.Metric is nil", 44 processKey: &metricIsNilProcessorKey, 45 want: nil, 46 wantErr: true, 47 }, 48 { 49 name: "not found NamespacedName", 50 processKey: ¬ExistNamespacedNameProcessorKey, 51 want: nil, 52 wantErr: true, 53 }, 54 { 55 name: "not found Metric", 56 processKey: ¬ExistMetricProcessorKey, 57 want: nil, 58 wantErr: true, 59 }, 60 { 61 name: "not found Task", 62 processKey: ¬FoundTaskProcessorKey, 63 want: nil, 64 wantErr: true, 65 }, 66 { 67 name: "task type illegal", 68 processKey: &valueTypeIllegalProcessorKey, 69 want: nil, 70 wantErr: true, 71 }, 72 { 73 name: "success", 74 processKey: &mockProcessKey1, 75 want: mockTask1, 76 wantErr: false, 77 }, 78 } 79 for _, tt := range tests { 80 t.Run(tt.name, func(t *testing.T) { 81 got, err := mockProcessor.getTaskForProcessKey(tt.processKey) 82 if (err != nil) != tt.wantErr { 83 t.Errorf("getTaskForProcessKey() error = %v, wantErr %v", err, tt.wantErr) 84 return 85 } 86 if !reflect.DeepEqual(got, tt.want) { 87 t.Errorf("getTaskForProcessKey() got = %v, want %v", got, tt.want) 88 } 89 }) 90 } 91 }