5b63066c2c
* Create helpers which integrate with OpenTelemetry for diagnose collection * Go mod vendor * consul tls checks * draft for storage end to end check * Comments * Update vault/diagnose/helpers.go Co-authored-by: swayne275 <swayne275@gmail.com> * Add unit test/example * tweak output * More comments * add spot check concept * Get unit tests working on Result structs * Fix unit test * Get unit tests working, and make diagnose sessions local rather than global * Comments * Last comments * No need for init * :| * Fix helpers_test * cleaned up chan logic. Tests next. * fix tests * remove a comment * tests * remove a comment * cosmetic changes Co-authored-by: Scott G. Miller <smiller@hashicorp.com> Co-authored-by: swayne275 <swayne275@gmail.com>
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package diagnose
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/hashicorp/vault/sdk/physical"
|
|
)
|
|
|
|
const (
|
|
timeoutCallRead string = "lag Read"
|
|
timeoutCallWrite string = "lag Write"
|
|
timeoutCallDelete string = "lag Delete"
|
|
errCallWrite string = "err Write"
|
|
errCallDelete string = "err Delete"
|
|
errCallRead string = "err Read"
|
|
badReadCall string = "bad Read"
|
|
storageErrStringWrite string = "storage error on write"
|
|
storageErrStringRead string = "storage error on read"
|
|
storageErrStringDelete string = "storage error on delete"
|
|
readOp string = "read"
|
|
writeOp string = "write"
|
|
deleteOp string = "delete"
|
|
)
|
|
|
|
var goodEntry physical.Entry = physical.Entry{Key: secretKey, Value: []byte(secretVal)}
|
|
var badEntry physical.Entry = physical.Entry{}
|
|
|
|
type mockStorageBackend struct {
|
|
callType string
|
|
}
|
|
|
|
func (m mockStorageBackend) storageLogicGeneralInternal(op string) error {
|
|
if (m.callType == timeoutCallRead && op == readOp) || (m.callType == timeoutCallWrite && op == writeOp) ||
|
|
(m.callType == timeoutCallDelete && op == deleteOp) {
|
|
time.Sleep(25 * time.Second)
|
|
} else if m.callType == errCallWrite && op == writeOp {
|
|
return fmt.Errorf(storageErrStringWrite)
|
|
} else if m.callType == errCallDelete && op == deleteOp {
|
|
return fmt.Errorf(storageErrStringDelete)
|
|
} else if m.callType == errCallRead && op == readOp {
|
|
return fmt.Errorf(storageErrStringRead)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Put is used to insert or update an entry
|
|
func (m mockStorageBackend) Put(ctx context.Context, entry *physical.Entry) error {
|
|
return m.storageLogicGeneralInternal(writeOp)
|
|
}
|
|
|
|
// Get is used to fetch an entry
|
|
func (m mockStorageBackend) Get(ctx context.Context, key string) (*physical.Entry, error) {
|
|
if m.callType == errCallRead || m.callType == timeoutCallRead {
|
|
return nil, m.storageLogicGeneralInternal(readOp)
|
|
}
|
|
if m.callType == badReadCall {
|
|
return &badEntry, nil
|
|
}
|
|
return &goodEntry, nil
|
|
|
|
}
|
|
|
|
// Delete is used to permanently delete an entry
|
|
func (m mockStorageBackend) Delete(ctx context.Context, key string) error {
|
|
|
|
return m.storageLogicGeneralInternal(deleteOp)
|
|
}
|
|
|
|
// List is not used in a mock.
|
|
func (m mockStorageBackend) List(ctx context.Context, prefix string) ([]string, error) {
|
|
return nil, fmt.Errorf("method not implemented")
|
|
}
|