Repository: prometheus/prometheus
File: promql/promqltest/test_test.go (Go)

Code before:
			expectedError: `error in eval some_metric[1m] (line 6): invalid range vector definition "expect range vector from 10s"`,
		},
		"instant query with range result - result matches expected value": {
			input: `
				load 1m
				  some_metric{env="1"} 0+1x4
				  some_metric{env="2"} 0+2x4
				
				eval instant at 2m some_metric[2m]
				  expect range vector from 1m to 2m step 60s
					some_metric{env="1"} 1 2
					some_metric{env="2"} 2 4
			`,
		},
		"instant query with range result - result has a is missing a sample": {
			input: `
				load 1m
				  some_metric_with_stale_marker 0 1 stale 3
				
				eval instant at 3m some_metric_with_stale_marker[3m]
					expect range vector from 1m to 3m step 60s
					some_metric_with_stale_marker{} 1 2 3
			`,
			expectedError: `error in eval some_metric_with_stale_marker[3m] (line 5): expected 3 float points and 0 histogram points for {__name__="some_metric_with_stale_marker"}, but got 2 float points [1 @[60000] 3 @[180000]] and 0 histogram points []`,
		},
		"instant query with range result - result has a sample where non is expected": {
			input: `
				load 1m
				  some_metric_with_stale_marker 0 1 2 3
				
				eval instant at 3m some_metric_with_stale_marker[3m]
					expect range vector from 1m to 3m step 60s
					some_metric_with_stale_marker{} 1 _ 3
			`,
			expectedError: `error in eval some_metric_with_stale_marker[3m] (line 5): expected 2 float points and 0 histogram points for {__name__="some_metric_with_stale_marker"}, but got 3 float points [1 @[60000] 2 @[120000] 3 @[180000]] and 0 histogram points []`,
		},
	}

	for name, testCase := range testCases {
		t.Run(name, func(t *testing.T) {
			err := testTest(t, testCase.input, NewTestEngine(t, false, 0, DefaultMaxSamplesPerQuery))

			if testCase.expectedError == "" {
				require.NoError(t, err)
			} else {
				require.EqualError(t, err, testCase.expectedError)
			}
		})
	}
}


Review comment (suggestion):
```suggestion
		"instant query with range result - result has a sample where none is expected": {
```

Code after:
			input: `
				load 10s
  					some_metric{env="a"} 1+1x5

				eval instant at 1m some_metric[1m]
					expect range vector from 10s to 1m step 10s
  					some_metric{env="a"} 9 3 4 5 6
			`,
			expectedError: `error in eval some_metric[1m] (line 5): expected float value at index 0 (t=10000) for {__name__="some_metric", env="a"} to be 9, but got 2 (result has 5 float points [2 @[10000] 3 @[20000] 4 @[30000] 5 @[40000] 6 @[50000]] and 0 histogram points [])`,
		},
		"instant query with range result - invalid expect range vector directive": {
			input: `
				load 10s
  					some_metric{env="a"} 1+1x5

				eval instant at 1m some_metric[1m]
					expect range vector from 10s
  					some_metric{env="a"} 2 3 4 5 6
			`,
			expectedError: `error in eval some_metric[1m] (line 6): invalid range vector definition "expect range vector from 10s"`,
		},
		"instant query with range result - result matches expected value": {
			input: `
				load 1m
				  some_metric{env="1"} 0+1x4
				  some_metric{env="2"} 0+2x4
				
				eval instant at 2m some_metric[2m]
				  expect range vector from 1m to 2m step 60s
					some_metric{env="1"} 1 2
					some_metric{env="2"} 2 4
			`,
		},
		"instant query with range result - result has a is missing a sample": {
			input: `
				load 1m
				  some_metric_with_stale_marker 0 1 stale 3
				
				eval instant at 3m some_metric_with_stale_marker[3m]
					expect range vector from 1m to 3m step 60s
					some_metric_with_stale_marker{} 1 2 3
			`,
			expectedError: `error in eval some_metric_with_stale_marker[3m] (line 5): expected 3 float points and 0 histogram points for {__name__="some_metric_with_stale_marker"}, but got 2 float points [1 @[60000] 3 @[180000]] and 0 histogram points []`,
		},
		"instant query with range result - result has a sample where none is expected": {
			input: `
				load 1m
				  some_metric_with_stale_marker 0 1 2 3
				
				eval instant at 3m some_metric_with_stale_marker[3m]
					expect range vector from 1m to 3m step 60s