Debian Codegraph @

cache/accessor/windows_test.go

raw
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3
4 //go:build windows
5 // +build windows
6
7 package accessor
8
9 import (
10 "encoding/json"
11 "os"
12 "path/filepath"
13 "testing"
14
15 "github.com/stretchr/testify/require"
16 )
17
18 func TestWriteEncryption(t *testing.T) {
19 p := filepath.Join(t.TempDir(), t.Name())
20 a, err := New(p)
21 require.NoError(t, err)
22
23 data := []byte(`{"key":"value"}`)
24 require.NoError(t, json.Unmarshal(data, &struct{}{}), "test bug: data should unmarshal")
25 require.NoError(t, a.Write(ctx, data))
26
27 // Write should have encrypted data before writing it to the file
28 actual, err := os.ReadFile(p)
29 require.NoError(t, err)
30 require.NotEmpty(t, actual)
31 err = json.Unmarshal(actual, &struct{}{})
32 require.Error(t, err, "Unmarshal should fail because the file's content, being encrypted, isn't JSON")
33 }