Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require-error: minimize false positives #5

Closed
Antonboom opened this issue Oct 4, 2023 · 1 comment
Closed

require-error: minimize false positives #5

Antonboom opened this issue Oct 4, 2023 · 1 comment
Assignees
Labels
false-positive Checker's false positive example

Comments

@Antonboom
Copy link
Owner

Antonboom commented Oct 4, 2023

Looks like no difference in

func TestGetDocFileWithLongLine(t *testing.T) {
	fpath := filepath.Join("testdata", "autogen_exclude_long_line.go")
	_, err := getDoc(fpath)
	assert.NoError(t, err) // <---
}

Precondition:

  1. No assertions more except error
  2. Or no operations after assertion at all

More examples:

k8s
	for _, name := range expectedCertificates {
		_, err = pkiutil.TryLoadKeyFromDisk(certDir, name)
		assert.NoErrorf(t, err, "failed to load key file: %s", name)

		_, err = pkiutil.TryLoadCSRFromDisk(certDir, name)
		assert.NoError(t, err, "failed to load CSR file: %s", name)
	}
	for _, testCase := range testCases {
		assert.NoError(t, scheme.Convert(testCase.obj1, testCase.obj2, nil))
		assert.NoError(t, scheme.Convert(testCase.obj2, testCase.obj1, nil))
	}
	for _, test := range tests {
		err := ValidateAppArmorProfileFormat(test.profile)
		if test.expectValid {
			assert.NoError(t, err, "Profile %s should be valid", test.profile)
		} else {
			assert.Error(t, err, fmt.Sprintf("Profile %s should not be valid", test.profile))
		}
	}
		redirect, err := kubelet.GetPortForward(ctx, tc.podName, podNamespace, podUID, portforward.V4Options{})
		if tc.expectError {
			assert.Error(t, err, description)
		} else {
			assert.NoError(t, err, description)
			assert.Equal(t, containertest.FakeHost, redirect.Host, description+": redirect")
		}
	for _, testcase := range testcases {
		actual, err := loadDriverDefinition(testcase.filename)
		if testcase.err == "" {
			assert.NoError(t, err, testcase.name)
		} else {
			if assert.Error(t, err, testcase.name) {
				assert.Equal(t, testcase.err, err.Error())
			}
		}
		if err == nil {
			assert.Equal(t, testcase.expected, actual)
		}
	}
Grafana
	t.Cleanup(func() {
		err := resp.Body.Close()
		assert.NoError(t, err)
	})
	compareResponses := func(expected *NormalResponse, actual *NormalResponse, compareErr bool) func(t *testing.T) {
		return func(t *testing.T) {
			if expected == nil {
				require.Nil(t, actual)
				return
			}

			require.NotNil(t, actual)
			assert.Equal(t, expected.status, actual.status)
			if expected.body != nil {
				assert.Equal(t, expected.body.Bytes(), actual.body.Bytes())
			}
			if expected.header != nil {
				assert.EqualValues(t, expected.header, actual.header)
			}
			assert.Equal(t, expected.errMessage, actual.errMessage)
			if compareErr {
				assert.ErrorIs(t, expected.err, actual.err)
			}
		}
	}
@Antonboom Antonboom added the good first issue Good for newcomers label Oct 4, 2023
@Antonboom Antonboom changed the title require-error checker: add ignore-single-assertion option (default false) require-error checker: add ignore-single-assertion option Oct 24, 2023
@Antonboom Antonboom removed the good first issue Good for newcomers label Oct 25, 2023
@Antonboom Antonboom self-assigned this Oct 25, 2023
@Antonboom Antonboom changed the title require-error checker: add ignore-single-assertion option require-error checker: minimize false positives Oct 26, 2023
@Antonboom Antonboom changed the title require-error checker: minimize false positives require-error: minimize false positives Oct 28, 2023
@Antonboom Antonboom added the false-positive Checker's false positive example label Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive Checker's false positive example
Projects
None yet
Development

No branches or pull requests

1 participant