unifiedmonitor_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019 Yunion
  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. package monitor
  15. import (
  16. "reflect"
  17. "testing"
  18. api "yunion.io/x/onecloud/pkg/apis/monitor"
  19. )
  20. func TestMetricQueryOptions_parseReducer(t *testing.T) {
  21. tests := []struct {
  22. reducer string
  23. want *api.Condition
  24. wantErr bool
  25. }{
  26. {
  27. reducer: "avg",
  28. want: &api.Condition{
  29. Type: "avg",
  30. },
  31. },
  32. {
  33. reducer: "percentile(95)",
  34. want: &api.Condition{
  35. Type: "percentile",
  36. Params: []float64{95},
  37. },
  38. },
  39. }
  40. for _, tt := range tests {
  41. t.Run(tt.reducer, func(t *testing.T) {
  42. o := MetricQueryOptions{}
  43. got, err := o.parseReducer(tt.reducer)
  44. if (err != nil) != tt.wantErr {
  45. t.Errorf("parseReducer() error = %v, wantErr %v", err, tt.wantErr)
  46. return
  47. }
  48. if !reflect.DeepEqual(got, tt.want) {
  49. t.Errorf("parseReducer() got = %v, want %v", got, tt.want)
  50. }
  51. })
  52. }
  53. }