go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers-sdk/v1/vault/inmemory/inmemory_test.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package inmemory
     5  
     6  import (
     7  	"context"
     8  	"encoding/json"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  	"go.mondoo.com/cnquery/providers-sdk/v1/vault"
    14  )
    15  
    16  func TestVault(t *testing.T) {
    17  	v := New()
    18  	ctx := context.Background()
    19  
    20  	credSecret := map[string]string{
    21  		"key":  "value",
    22  		"key2": "value2",
    23  	}
    24  	credBytes, err := json.Marshal(credSecret)
    25  	require.NoError(t, err)
    26  
    27  	key := "mondoo-test-secret-key"
    28  	cred := &vault.Secret{
    29  		Key:      key,
    30  		Label:    "mondoo: " + key,
    31  		Data:     credBytes,
    32  		Encoding: vault.SecretEncoding_encoding_proto,
    33  	}
    34  
    35  	id, err := v.Set(ctx, cred)
    36  	require.NoError(t, err)
    37  
    38  	newCred, err := v.Get(ctx, id)
    39  	require.NoError(t, err)
    40  	assert.Equal(t, key, newCred.Key)
    41  	assert.Equal(t, cred.Label, newCred.Label)
    42  	assert.EqualValues(t, cred.Data, newCred.Data)
    43  }