| 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 (darwin && cgo) || (linux && cgo) || windows |
| 5 |
// +build darwin,cgo linux,cgo windows |
| 6 |
|
| 7 |
package accessor |
| 8 |
|
| 9 |
import ( |
| 10 |
"context" |
| 11 |
"os" |
| 12 |
"path/filepath" |
| 13 |
"runtime" |
| 14 |
"testing" |
| 15 |
|
| 16 |
"github.com/stretchr/testify/require" |
| 17 |
) |
| 18 |
|
| 19 |
const msalextManualTest = "MSALEXT_MANUAL_TEST" |
| 20 |
|
| 21 |
var ( |
| 22 |
ctx = context.Background() |
| 23 |
|
| 24 |
// the Windows implementation doesn't require user interaction |
| 25 |
manualTests = runtime.GOOS == "windows" || os.Getenv(msalextManualTest) != "" |
| 26 |
) |
| 27 |
|
| 28 |
func TestReadWriteDelete(t *testing.T) { |
| 29 |
if !manualTests { |
| 30 |
t.Skipf("set %s to run this test", msalextManualTest) |
| 31 |
} |
| 32 |
for _, test := range []struct { |
| 33 |
desc string |
| 34 |
want []byte |
| 35 |
}{ |
| 36 |
{desc: "Test when no stored data exists"}, |
| 37 |
{desc: "Test writing data then reading it", want: []byte("want")}, |
| 38 |
} { |
| 39 |
t.Run(test.desc, func(t *testing.T) { |
| 40 |
p := filepath.Join(t.TempDir(), t.Name()) |
| 41 |
a, err := New(p) |
| 42 |
require.NoError(t, err) |
| 43 |
|
| 44 |
if test.want != nil { |
| 45 |
cp := make([]byte, len(test.want)) |
| 46 |
copy(cp, test.want) |
| 47 |
err = a.Write(ctx, cp) |
| 48 |
require.NoError(t, err) |
| 49 |
} |
| 50 |
|
| 51 |
actual, err := a.Read(ctx) |
| 52 |
require.NoError(t, err) |
| 53 |
require.Equal(t, test.want, actual) |
| 54 |
|
| 55 |
require.NoError(t, a.Delete(context.Background())) |
| 56 |
}) |
| 57 |
} |
| 58 |
} |