2022-07-13 11:48:10 +02:00
// Copyright 2022 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2024-04-29 13:14:18 +01:00
package promql_test
2022-07-13 11:48:10 +02:00
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/prometheus/prometheus/model/labels"
2024-04-29 13:14:18 +01:00
"github.com/prometheus/prometheus/promql"
2022-07-13 11:48:10 +02:00
)
func TestVector_ContainsSameLabelset ( t * testing . T ) {
for name , tc := range map [ string ] struct {
2024-04-29 13:14:18 +01:00
vector promql . Vector
2022-07-13 11:48:10 +02:00
expected bool
} {
"empty vector" : {
2024-04-29 13:14:18 +01:00
vector : promql . Vector { } ,
2022-07-13 11:48:10 +02:00
expected : false ,
} ,
"vector with one series" : {
2024-04-29 13:14:18 +01:00
vector : promql . Vector {
2022-07-13 11:48:10 +02:00
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
} ,
expected : false ,
} ,
"vector with two different series" : {
2024-04-29 13:14:18 +01:00
vector : promql . Vector {
2022-07-13 11:48:10 +02:00
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
{ Metric : labels . FromStrings ( "lbl" , "b" ) } ,
} ,
expected : false ,
} ,
"vector with two equal series" : {
2024-04-29 13:14:18 +01:00
vector : promql . Vector {
2022-07-13 11:48:10 +02:00
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
} ,
expected : true ,
} ,
"vector with three series, two equal" : {
2024-04-29 13:14:18 +01:00
vector : promql . Vector {
2022-07-13 11:48:10 +02:00
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
{ Metric : labels . FromStrings ( "lbl" , "b" ) } ,
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
} ,
expected : true ,
} ,
} {
t . Run ( name , func ( t * testing . T ) {
require . Equal ( t , tc . expected , tc . vector . ContainsSameLabelset ( ) )
} )
}
}
func TestMatrix_ContainsSameLabelset ( t * testing . T ) {
for name , tc := range map [ string ] struct {
2024-04-29 13:14:18 +01:00
matrix promql . Matrix
2022-07-13 11:48:10 +02:00
expected bool
} {
"empty matrix" : {
2024-04-29 13:14:18 +01:00
matrix : promql . Matrix { } ,
2022-07-13 11:48:10 +02:00
expected : false ,
} ,
"matrix with one series" : {
2024-04-29 13:14:18 +01:00
matrix : promql . Matrix {
2022-07-13 11:48:10 +02:00
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
} ,
expected : false ,
} ,
"matrix with two different series" : {
2024-04-29 13:14:18 +01:00
matrix : promql . Matrix {
2022-07-13 11:48:10 +02:00
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
{ Metric : labels . FromStrings ( "lbl" , "b" ) } ,
} ,
expected : false ,
} ,
"matrix with two equal series" : {
2024-04-29 13:14:18 +01:00
matrix : promql . Matrix {
2022-07-13 11:48:10 +02:00
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
} ,
expected : true ,
} ,
"matrix with three series, two equal" : {
2024-04-29 13:14:18 +01:00
matrix : promql . Matrix {
2022-07-13 11:48:10 +02:00
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
{ Metric : labels . FromStrings ( "lbl" , "b" ) } ,
{ Metric : labels . FromStrings ( "lbl" , "a" ) } ,
} ,
expected : true ,
} ,
} {
t . Run ( name , func ( t * testing . T ) {
require . Equal ( t , tc . expected , tc . matrix . ContainsSameLabelset ( ) )
} )
}
}