open-vault/command/agent/cache/cachememdb/index_test.go
Brian Kassouf 303c2aee7c
Run a more strict formatter over the code (#11312)
* Update tooling

* Run gofumpt

* go mod vendor
2021-04-08 09:43:39 -07:00

43 lines
1.1 KiB
Go

package cachememdb
import (
"context"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSerializeDeserialize(t *testing.T) {
testIndex := &Index{
ID: "testid",
Token: "testtoken",
TokenParent: "parent token",
TokenAccessor: "test accessor",
Namespace: "test namespace",
RequestPath: "/test/path",
Lease: "lease id",
LeaseToken: "lease token id",
Response: []byte(`{"something": "here"}`),
RenewCtxInfo: NewContextInfo(context.Background()),
RequestMethod: "GET",
RequestToken: "request token",
RequestHeader: http.Header{
"X-Test": []string{"vault", "agent"},
},
LastRenewed: time.Now().UTC(),
}
indexBytes, err := testIndex.Serialize()
require.NoError(t, err)
assert.True(t, len(indexBytes) > 0)
assert.NotNil(t, testIndex.RenewCtxInfo, "Serialize should not modify original Index object")
restoredIndex, err := Deserialize(indexBytes)
require.NoError(t, err)
testIndex.RenewCtxInfo = nil
assert.Equal(t, testIndex, restoredIndex, "They should be equal without RenewCtxInfo set on the original")
}