Skip to content

Commit 0a83e38

Browse files
committed
Add autocertcache test
1 parent 06bb785 commit 0a83e38

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

autocertcache/cache_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2021-2023 TTBT Enterprises LLC
4+
// Copyright (c) 2021-2023 Robin Thellend <rthellend@rthellend.com>
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
24+
package autocertcache_test
25+
26+
import (
27+
"context"
28+
"testing"
29+
30+
"github.com/c2FmZQ/storage"
31+
"github.com/c2FmZQ/storage/autocertcache"
32+
"github.com/c2FmZQ/storage/crypto"
33+
"golang.org/x/crypto/acme/autocert"
34+
)
35+
36+
func TestCache(t *testing.T) {
37+
ctx := context.Background()
38+
mk, err := crypto.CreateMasterKey()
39+
if err != nil {
40+
t.Fatalf("crypto.CreateMasterKey: %v", err)
41+
}
42+
defer mk.Wipe()
43+
cache := autocertcache.New("autocert", storage.New(t.TempDir(), mk))
44+
45+
if v, err := cache.Get(ctx, "foo"); err != autocert.ErrCacheMiss || v != nil {
46+
t.Errorf("cache.Get(foo) = %v, %v, want nil, ErrCacheMiss", v, err)
47+
}
48+
if err := cache.Put(ctx, "foo", []byte("bar")); err != nil {
49+
t.Errorf("cache.Put(foo, bar) = %v", err)
50+
}
51+
if v, err := cache.Get(ctx, "foo"); err != nil || string(v) != "bar" {
52+
t.Errorf("cache.Get(foo) = %q, %v, want bar, nil", v, err)
53+
}
54+
if err := cache.Delete(ctx, "foo"); err != nil {
55+
t.Errorf("cache.Delete(foo) = %v", err)
56+
}
57+
if v, err := cache.Get(ctx, "foo"); err != autocert.ErrCacheMiss || v != nil {
58+
t.Errorf("cache.Get(foo) = %v, %v, want nil, ErrCacheMiss", v, err)
59+
}
60+
}

0 commit comments

Comments
 (0)