Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Vault
Commits
2dc0d225
Unverified
Commit
2dc0d225
authored
5 years ago
by
catsby
Browse files
Options
Download
Email Patches
Plain Diff
wrap in helper()
parent
9968a59b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
builtin/logical/transit/stepwise_test.go
+5
-5
builtin/logical/transit/stepwise_test.go
sdk/testing/stepwise/testing.go
+29
-24
sdk/testing/stepwise/testing.go
with
34 additions
and
29 deletions
+34
-29
builtin/logical/transit/stepwise_test.go
+
5
-
5
View file @
2dc0d225
...
@@ -41,7 +41,7 @@ func testAccStepwiseWritePolicy(t *testing.T, name string, derived bool) stepwis
...
@@ -41,7 +41,7 @@ func testAccStepwiseWritePolicy(t *testing.T, name string, derived bool) stepwis
Data
:
map
[
string
]
interface
{}{
Data
:
map
[
string
]
interface
{}{
"derived"
:
derived
,
"derived"
:
derived
,
},
},
Check
:
func
(
resp
*
api
.
Secret
)
error
{
Check
:
func
(
resp
*
api
.
Secret
,
err
error
)
error
{
q
.
Q
(
"--> stepwise write policy check func"
)
q
.
Q
(
"--> stepwise write policy check func"
)
return
nil
return
nil
},
},
...
@@ -56,7 +56,7 @@ func testAccStepwiseListPolicy(t *testing.T, name string, expectNone bool) stepw
...
@@ -56,7 +56,7 @@ func testAccStepwiseListPolicy(t *testing.T, name string, expectNone bool) stepw
return
stepwise
.
Step
{
return
stepwise
.
Step
{
Operation
:
stepwise
.
ListOperation
,
Operation
:
stepwise
.
ListOperation
,
Path
:
"keys"
,
Path
:
"keys"
,
Check
:
func
(
resp
*
api
.
Secret
)
error
{
Check
:
func
(
resp
*
api
.
Secret
,
err
error
)
error
{
q
.
Q
(
"--> stepwise list check func"
)
q
.
Q
(
"--> stepwise list check func"
)
q
.
Q
(
"resp in check:"
,
resp
)
q
.
Q
(
"resp in check:"
,
resp
)
if
(
resp
==
nil
||
len
(
resp
.
Data
)
==
0
)
&&
!
expectNone
{
if
(
resp
==
nil
||
len
(
resp
.
Data
)
==
0
)
&&
!
expectNone
{
...
@@ -97,7 +97,7 @@ func testAccStepwiseReadPolicyWithVersions(t *testing.T, name string, expectNone
...
@@ -97,7 +97,7 @@ func testAccStepwiseReadPolicyWithVersions(t *testing.T, name string, expectNone
return
stepwise
.
Step
{
return
stepwise
.
Step
{
Operation
:
stepwise
.
ReadOperation
,
Operation
:
stepwise
.
ReadOperation
,
Path
:
"keys/"
+
name
,
Path
:
"keys/"
+
name
,
Check
:
func
(
resp
*
api
.
Secret
)
error
{
Check
:
func
(
resp
*
api
.
Secret
,
err
error
)
error
{
q
.
Q
(
"--> read policy check"
)
q
.
Q
(
"--> read policy check"
)
if
resp
==
nil
&&
!
expectNone
{
if
resp
==
nil
&&
!
expectNone
{
return
fmt
.
Errorf
(
"missing response"
)
return
fmt
.
Errorf
(
"missing response"
)
...
@@ -171,7 +171,7 @@ func testAccStepwiseEncryptContext(
...
@@ -171,7 +171,7 @@ func testAccStepwiseEncryptContext(
"plaintext"
:
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
plaintext
)),
"plaintext"
:
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
plaintext
)),
"context"
:
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
context
)),
"context"
:
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
context
)),
},
},
Check
:
func
(
resp
*
api
.
Secret
)
error
{
Check
:
func
(
resp
*
api
.
Secret
,
err
error
)
error
{
var
d
struct
{
var
d
struct
{
Ciphertext
string
`mapstructure:"ciphertext"`
Ciphertext
string
`mapstructure:"ciphertext"`
}
}
...
@@ -194,7 +194,7 @@ func testAccStepwiseDecrypt(
...
@@ -194,7 +194,7 @@ func testAccStepwiseDecrypt(
Operation
:
stepwise
.
UpdateOperation
,
Operation
:
stepwise
.
UpdateOperation
,
Path
:
"decrypt/"
+
name
,
Path
:
"decrypt/"
+
name
,
Data
:
decryptData
,
Data
:
decryptData
,
Check
:
func
(
resp
*
api
.
Secret
)
error
{
Check
:
func
(
resp
*
api
.
Secret
,
err
error
)
error
{
var
d
struct
{
var
d
struct
{
Plaintext
string
`mapstructure:"plaintext"`
Plaintext
string
`mapstructure:"plaintext"`
}
}
...
...
This diff is collapsed.
Click to expand it.
sdk/testing/stepwise/testing.go
+
29
-
24
View file @
2dc0d225
...
@@ -68,7 +68,7 @@ type Step struct {
...
@@ -68,7 +68,7 @@ type Step struct {
}
}
// StepCheckFunc is the callback used for Check in TestStep.
// StepCheckFunc is the callback used for Check in TestStep.
type
StepCheckFunc
func
(
*
api
.
Secret
)
error
type
StepCheckFunc
func
(
*
api
.
Secret
,
error
)
error
// StepDriver is the interface Drivers need to implement to be used in
// StepDriver is the interface Drivers need to implement to be used in
// Case to execute each Step
// Case to execute each Step
...
@@ -100,6 +100,12 @@ type Case struct {
...
@@ -100,6 +100,12 @@ type Case struct {
Teardown
TestTeardownFunc
Teardown
TestTeardownFunc
}
}
// Check wraps a StepCheckFunc with t.Helper() call
func
(
c
*
Case
)
Check
(
tt
TestT
,
s
*
api
.
Secret
,
err
error
,
cf
StepCheckFunc
)
error
{
tt
.
Helper
()
return
cf
(
s
,
err
)
}
// Run performs an acceptance test on a backend with the given test case.
// Run performs an acceptance test on a backend with the given test case.
//
//
// Tests are not run unless an environmental variable "VAULT_ACC" is
// Tests are not run unless an environmental variable "VAULT_ACC" is
...
@@ -197,8 +203,6 @@ func Run(tt TestT, c Case) {
...
@@ -197,8 +203,6 @@ func Run(tt TestT, c Case) {
case
ListOperation
:
case
ListOperation
:
q
.
Q
(
"===> List operation"
)
q
.
Q
(
"===> List operation"
)
resp
,
err
=
client
.
Logical
()
.
List
(
path
)
resp
,
err
=
client
.
Logical
()
.
List
(
path
)
// TODO why though
// lr = &logical.Response{}
case
DeleteOperation
:
case
DeleteOperation
:
q
.
Q
(
"===> Delete operation"
)
q
.
Q
(
"===> Delete operation"
)
resp
,
err
=
client
.
Logical
()
.
Delete
(
path
)
resp
,
err
=
client
.
Logical
()
.
Delete
(
path
)
...
@@ -238,20 +242,20 @@ func Run(tt TestT, c Case) {
...
@@ -238,20 +242,20 @@ func Run(tt TestT, c Case) {
//
//
// Test step returned an error.
// Test step returned an error.
if
err
!=
nil
{
//
if err != nil {
// But if an error is expected, do not fail the test step,
//
// But if an error is expected, do not fail the test step,
// regardless of whether the error is a 'logical.ErrorResponse'
//
// regardless of whether the error is a 'logical.ErrorResponse'
// or not. Set the err to nil. If the error is a logical.ErrorResponse,
//
// or not. Set the err to nil. If the error is a logical.ErrorResponse,
// it will be handled later.
//
// it will be handled later.
if
s
.
ErrorOk
{
//
if s.ErrorOk {
q
.
Q
(
"===> error ok, setting to nil"
)
//
q.Q("===> error ok, setting to nil")
err
=
nil
//
err = nil
}
else
{
//
} else {
// // If the error is not expected, fail right away.
//
// // If the error is not expected, fail right away.
tt
.
Error
(
fmt
.
Sprintf
(
"Failed step %d: %s"
,
i
+
1
,
err
))
//
tt.Error(fmt.Sprintf("Failed step %d: %s", i+1, err))
break
//
break
}
//
}
}
//
}
// TODO
// TODO
// - test check func here
// - test check func here
...
@@ -260,13 +264,13 @@ func Run(tt TestT, c Case) {
...
@@ -260,13 +264,13 @@ func Run(tt TestT, c Case) {
// Either the 'err' was nil or if an error was expected, it was set to nil.
// Either the 'err' was nil or if an error was expected, it was set to nil.
// Call the 'Check' function if there is one.
// Call the 'Check' function if there is one.
//
//
// TODO: This works perfectly for now, but it would be better if 'Check'
var
checkErr
error
// function takes in both the response object and the error, and decide on
if
s
.
Check
!=
nil
{
// the action on its own.
checkErr
=
c
.
Check
(
tt
,
resp
,
err
,
s
.
Check
)
if
err
==
nil
&&
s
.
Check
!=
nil
{
// checkErr = s.Check(resp,err)
// Call the test method
}
// TODO check here
if
checkErr
!=
nil
{
err
=
s
.
Check
(
resp
)
tt
.
Error
(
"test check error:"
,
checkErr
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -406,6 +410,7 @@ type TestT interface {
...
@@ -406,6 +410,7 @@ type TestT interface {
Error
(
args
...
interface
{})
Error
(
args
...
interface
{})
Fatal
(
args
...
interface
{})
Fatal
(
args
...
interface
{})
Skip
(
args
...
interface
{})
Skip
(
args
...
interface
{})
Helper
()
}
}
var
testTesting
=
false
var
testTesting
=
false
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment