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

Update test template to exclude deepsource warning #1954

Merged
merged 6 commits into from
Mar 3, 2023

Conversation

kevindiu
Copy link
Contributor

@kevindiu kevindiu commented Feb 21, 2023

Description:

This PR update the gotests test template to exclude the type on the generated test file.
These types are warned in deepsource before, including the following type:

  • sync.Map
  • sync.Mutex
  • sync.RWMutex
  • sync.Once
  • sync.Map
  • sync.WaitGroup
  • sync.Pool
  • sync.Cond
  • (other custom type contains lock)

Custom type exclusion will not be included in this PR.

You can verify this changes by using make gotests/gen command to generate the missing test impl and verify the changes using git diff [file].
e.g. git diff internal/circuitbreaker/manager_test.go

func Test_breakerManager_Do(t *testing.T) {
        type args struct {
                ctx context.Context
                key string
                fn  func(ctx context.Context) (interface{}, error)
        }
        type fields struct {
                opts []BreakerOption
        }
        type want struct {
                wantVal interface{}
                err     error
        }
        type test struct {
                name       string
                args       args
                fields     fields
                want       want
                checkFunc  func(want, interface{}, error) error
                beforeFunc func(*testing.T, args)
                afterFunc  func(*testing.T, args)
        }
        defaultCheckFunc := func(w want, gotVal interface{}, err error) error {
                if !errors.Is(err, w.err) {
                        return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err)
                }
                if !reflect.DeepEqual(gotVal, w.wantVal) {
                        return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotVal, w.wantVal)
                }
                return nil
        }
        tests := []test{
                // TODO test cases
                /*
                   {
                       name: "test_case_1",
                       args: args {
                           ctx:nil,
                           key:"",
                           fn:nil,
                       },
                       fields: fields {
                           opts:nil,
                       },
                       want: want{},
                       checkFunc: defaultCheckFunc,
                       beforeFunc: func(t *testing.T, args args) {
                           t.Helper()
                       },
                       afterFunc: func(t *testing.T, args args) {
                           t.Helper()
                       },
                   },
                */

                // TODO test cases
                /*
                   func() test {
                       return test {
                           name: "test_case_2",
                           args: args {
                           ctx:nil,
                           key:"",
                           fn:nil,
                           },
                           fields: fields {
                           opts:nil,
                           },
                           want: want{},
                           checkFunc: defaultCheckFunc,
                           beforeFunc: func(t *testing.T, args args) {
                               t.Helper()
                           },
                           afterFunc: func(t *testing.T, args args) {
                               t.Helper()
                           },
                       }
                   }(),
                */
        }

        for _, tc := range tests {
                test := tc
                t.Run(test.name, func(tt *testing.T) {
                        tt.Parallel()
                        defer goleak.VerifyNone(tt, goleak.IgnoreCurrent())
                        if test.beforeFunc != nil {
                                test.beforeFunc(tt, test.args)
                        }
                        if test.afterFunc != nil {
                                defer test.afterFunc(tt, test.args)
                        }
                        checkFunc := test.checkFunc
                        if test.checkFunc == nil {
                                checkFunc = defaultCheckFunc
                        }
                        bm := &breakerManager{
                                opts: test.fields.opts,
                        }

                        gotVal, err := bm.Do(test.args.ctx, test.args.key, test.args.fn)
                        if err := checkFunc(test.want, gotVal, err); err != nil {
                                tt.Errorf("error = %v", err)
                        }

                })
        }
}

Related Issue:

Versions:

  • Go Version: 1.20
  • Docker Version: 20.10.8
  • Kubernetes Version: 1.22.0
  • NGT Version: 2.0.9

Checklist:

Special notes for your reviewer:

@vdaas-ci
Copy link
Collaborator

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 💌 /changelog - replace the PR body by changelog details
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • /rebase - rebase main
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

@cloudflare-pages
Copy link

cloudflare-pages bot commented Feb 27, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6fd85f7
Status: ✅  Deploy successful!
Preview URL: https://1e8729dd.vald.pages.dev
Branch Preview URL: https://refactor-update-test-templat.vald.pages.dev

View logs

@kevindiu kevindiu changed the title [WIP] Update test template Update test template to exclude deepsource warning Feb 27, 2023
@kevindiu kevindiu marked this pull request as ready for review February 27, 2023 03:14
@kevindiu kevindiu requested review from vankichi, a team and hlts2 and removed request for a team February 27, 2023 03:14
@kevindiu
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by kevindiu for branch: refactor/update-test-template-no-sync-field

@vdaas-ci
Copy link
Collaborator

[REBASE] Failed to rebase.

@kevindiu kevindiu force-pushed the refactor/update-test-template-no-sync-field branch from 870a97a to 16cb3aa Compare February 27, 2023 06:58
vankichi
vankichi previously approved these changes Feb 28, 2023
vankichi
vankichi previously approved these changes Mar 1, 2023
hlts2
hlts2 previously approved these changes Mar 3, 2023
@kevindiu kevindiu force-pushed the refactor/update-test-template-no-sync-field branch from 529844b to 7603233 Compare March 3, 2023 01:47
@kevindiu kevindiu requested a review from hlts2 March 3, 2023 01:47
Signed-off-by: kevindiu <kevin_diu@yahoo.com.hk>
Signed-off-by: kevindiu <kevin_diu@yahoo.com.hk>
Signed-off-by: kevindiu <kevin_diu@yahoo.com.hk>
Signed-off-by: kevindiu <kevin_diu@yahoo.com.hk>
Signed-off-by: kevindiu <kevin_diu@yahoo.com.hk>
Signed-off-by: kevindiu <kevin_diu@yahoo.com.hk>
@kevindiu kevindiu force-pushed the refactor/update-test-template-no-sync-field branch from 7603233 to 6fd85f7 Compare March 3, 2023 01:54
@kevindiu kevindiu merged commit f4b9404 into main Mar 3, 2023
@kevindiu kevindiu deleted the refactor/update-test-template-no-sync-field branch March 3, 2023 02:40
@kpango kpango mentioned this pull request Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants