-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure all mount errors are covered (#2289)
* CI: Test against vault enterprise 1.17.1 and bump other versions * Build: Add support running tests using gotestsum * CI: Drop 1.11.12-ent
- Loading branch information
Showing
23 changed files
with
282 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package mountutil | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/api" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsMountNotFoundError(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
err error | ||
want bool | ||
}{ | ||
{ | ||
name: "with-err-mount-not-found", | ||
err: ErrMountNotFound, | ||
want: true, | ||
}, | ||
{ | ||
name: "with-response-error-no-secret-engine-mount", | ||
err: &api.ResponseError{ | ||
StatusCode: http.StatusBadRequest, | ||
Errors: []string{ | ||
"No secret engine mount at auth/operator/", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "with-response-error-no-auth-engine-mount", | ||
err: &api.ResponseError{ | ||
StatusCode: http.StatusBadRequest, | ||
Errors: []string{ | ||
"No auth engine at auth/operator/", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "with-response-error-both", | ||
err: &api.ResponseError{ | ||
StatusCode: http.StatusBadRequest, | ||
Errors: []string{ | ||
"No secret engine mount at auth/operator/", | ||
"No auth engine at auth/operator/", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "with-response-error-others", | ||
err: &api.ResponseError{ | ||
StatusCode: http.StatusBadRequest, | ||
Errors: []string{ | ||
"Some other error", | ||
"No auth engine at auth/operator/", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "with-not-found-status-code", | ||
err: &api.ResponseError{ | ||
StatusCode: http.StatusNotFound, | ||
Errors: []string{ | ||
"some error", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "with-response-error-canary", | ||
err: &api.ResponseError{ | ||
StatusCode: http.StatusBadRequest, | ||
Errors: []string{ | ||
"secret engine mount", | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "with-nil-error", | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.want, IsMountNotFoundError(tt.err), "IsMountNotFoundError(%v)", tt.err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.