Skip to content

Commit

Permalink
Merge pull request #109 from cortexproject/add_test_case_utf8_string
Browse files Browse the repository at this point in the history
Add possible selector label value of . to cover more non existent value
  • Loading branch information
yeya24 committed Mar 28, 2024
2 parents c2a9ca1 + a5ecbe9 commit 5e341f0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,22 @@ func (s *PromQLSmith) walkSelectors() []*labels.Matcher {
value = ""
} else if val > 0.9 {
value = "not_exist_value"
} else if val > 0.8 {
// TODO: randomize the non existent value using random UTF8 runes.
value = "."
} else {
idx := s.rnd.Intn(len(s.labelValues[name]))
value = s.labelValues[name][idx]
}
case labels.MatchNotEqual:
switch s.rnd.Intn(3) {
switch s.rnd.Intn(4) {
case 0:
value = ""
case 1:
value = "not_exist_value"
case 2:
// TODO: randomize the non existent value using random UTF8 runes.
value = "."
default:
idx := s.rnd.Intn(len(s.labelValues[name]))
value = s.labelValues[name][idx]
Expand All @@ -378,6 +384,9 @@ func (s *PromQLSmith) walkSelectors() []*labels.Matcher {
value = ""
} else if val > 0.9 {
value = "not_exist_value"
} else if val > 0.85 {
// TODO: randomize the non existent value using random UTF8 runes.
value = "."
} else if val > 0.8 {
value = ".*"
} else if val > 0.7 {
Expand Down Expand Up @@ -405,8 +414,11 @@ func (s *PromQLSmith) walkSelectors() []*labels.Matcher {
val := s.rnd.Float64()
if val > 0.8 {
value = ""
} else if val > 0.6 {
} else if val > 0.7 {
value = "not_exist_value"
} else if val > 0.6 {
// TODO: randomize the non existent value using random UTF8 runes.
value = "."
} else if val > 0.4 {
// Prefix
idx := s.rnd.Intn(len(s.labelValues[name]))
Expand Down

0 comments on commit 5e341f0

Please sign in to comment.