dnaeon / go-vcr

Record and replay your HTTP interactions for fast, deterministic and accurate tests
BSD 2-Clause "Simplified" License
1.26k stars 78 forks source link

After some time certain interactions are not found even though they are in the cassette. #106

Closed ilijamt closed 1 month ago

ilijamt commented 1 month ago

I have a very weird issue. The tests pass for some time and after that they stop working. This only happens on some tests.

It errors out with

Run go test -cover -coverprofile=coverage.out
--- FAIL: TestGitlabClient_CreateAccessToken_And_Revoke (0.00s)
    gitlab_client_test.go:229: 
            Error Trace:    /home/runner/work/vault-plugin-secrets-gitlab/vault-plugin-secrets-gitlab/gitlab_client_test.go:229
            Error:          Received unexpected error:
                            Post "http://localhost:8080/api/v4/groups/example/access_tokens": requested interaction not found
            Test:           TestGitlabClient_CreateAccessToken_And_Revoke
--- FAIL: TestGitlabClient_RotateCurrentToken (0.46s)
    gitlab_client_test.go:276: 
            Error Trace:    /home/runner/work/vault-plugin-secrets-gitlab/vault-plugin-secrets-gitlab/gitlab_client_test.go:276
            Error:          Received unexpected error:
                            Post "http://localhost:8080/api/v4/personal_access_tokens/6/rotate": requested interaction not found
            Test:           TestGitlabClient_RotateCurrentToken
--- FAIL: TestPathTokenRolesMultipleConfigs (0.15s)
    path_token_role_multiple_config_test.go:93: 
            Error Trace:    /home/runner/work/vault-plugin-secrets-gitlab/vault-plugin-secrets-gitlab/path_token_role_multiple_config_test.go:93
            Error:          Received unexpected error:
                            Post "http://localhost:8080/api/v4/users/1/personal_access_tokens": requested interaction not found
            Test:           TestPathTokenRolesMultipleConfigs
--- FAIL: TestWithAdminUser_PAT_AdminUser_GitlabRevokesToken (0.44s)
    with_admin_user_pat_gitlab_revokes_token_test.go:76: 
            Error Trace:    /home/runner/work/vault-plugin-secrets-gitlab/vault-plugin-secrets-gitlab/with_admin_user_pat_gitlab_revokes_token_test.go:76
            Error:          Received unexpected error:
                            Post "http://localhost:8080/api/v4/users/3/personal_access_tokens": requested interaction not found
            Test:           TestWithAdminUser_PAT_AdminUser_GitlabRevokesToken
--- FAIL: TestWithAdminUser_PAT_AdminUser_VaultRevokesToken (0.15s)
    with_admin_user_pat_vault_revokes_token_test.go:77: 
            Error Trace:    /home/runner/work/vault-plugin-secrets-gitlab/vault-plugin-secrets-gitlab/with_admin_user_pat_vault_revokes_token_test.go:77
            Error:          Received unexpected error:
                            Post "http://localhost:8080/api/v4/users/2/personal_access_tokens": requested interaction not found
            Test:           TestWithAdminUser_PAT_AdminUser_VaultRevokesToken
--- FAIL: TestWithNormalUser_GAT (0.02s)
    with_normal_user_gat_test.go:72: 
            Error Trace:    /home/runner/work/vault-plugin-secrets-gitlab/vault-plugin-secrets-gitlab/with_normal_user_gat_test.go:72
            Error:          Received unexpected error:
                            Post "http://localhost:8080/api/v4/groups/example/access_tokens": requested interaction not found
            Test:           TestWithNormalUser_GAT
--- FAIL: TestWithNormalUser_PersonalAT_Fails (0.10s)
    with_normal_user_personal_at_fails_test.go:72: 
            Error Trace:    /home/runner/work/vault-plugin-secrets-gitlab/vault-plugin-secrets-gitlab/with_normal_user_personal_at_fails_test.go:72
            Error:          Error "Post \"http://localhost:8080/api/v4/users/3/personal_access_tokens\": requested interaction not found" does not contain "403 Forbidden"
            Test:           TestWithNormalUser_PersonalAT_Fails
--- FAIL: TestWithNormalUser_ProjectAT (0.04s)
    with_normal_user_project_at_test.go:77: 
            Error Trace:    /home/runner/work/vault-plugin-secrets-gitlab/vault-plugin-secrets-gitlab/with_normal_user_project_at_test.go:77
            Error:          Received unexpected error:
                            Post "http://localhost:8080/api/v4/projects/example%2Fexample/access_tokens": requested interaction not found

You can see that only certain tests fail. And they fail usually after some time has passed.

But if you look in the yaml file all the interactions are there.

Do you have any idea why they fail occasionally.

If I regenerate the cassettes, it will work for some time and then it will stop again.

Here is one of the cassettes. Do you know what is going on? Maybe I'm missing something.

https://github.com/ilijamt/vault-plugin-secrets-gitlab/blob/main/testdata/fixtures/16.11.6/TestGitlabClient_CreateAccessToken_And_Revoke.yaml

And here is the recorder is implemented bellow

https://github.com/ilijamt/vault-plugin-secrets-gitlab/blob/0d125712a1ca86edcacac8e6aa3091b63b6431e5/gitlab_record_client_test.go#L14

ilijamt commented 1 month ago

Found the issue, the date and time that was returned was changing, and after a day it no longer matches.