blob: 5ed5314478df292a2ce1f34b6f6471183730dbee [file] [log] [blame]
// Copyright 2017 The LUCI Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cachingtest
import (
"context"
"errors"
"testing"
"go.chromium.org/luci/server/caching"
. "github.com/smartystreets/goconvey/convey"
)
func TestWorks(t *testing.T) {
t.Parallel()
Convey("Works", t, func() {
c := context.Background()
b := NewBlobCache()
res, err := b.Get(c, "key")
So(res, ShouldBeNil)
So(err, ShouldEqual, caching.ErrCacheMiss)
So(b.Set(c, "key", []byte("blah"), 0), ShouldBeNil)
res, err = b.Get(c, "key")
So(res, ShouldResemble, []byte("blah"))
So(err, ShouldBeNil)
})
Convey("Errors", t, func() {
fail := errors.New("fail")
c := context.Background()
b := NewBlobCache()
b.Err = fail
_, err := b.Get(c, "key")
So(err, ShouldEqual, fail)
So(b.Set(c, "key", nil, 0), ShouldEqual, fail)
})
}