2018-12-17 05:27:07 -05:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-09-28 16:18:51 -04:00
|
|
|
"github.com/docker/docker/errdefs"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2018-12-17 05:27:07 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTlsCreateUpdateGetRemove(t *testing.T) {
|
2022-02-25 08:37:07 -05:00
|
|
|
testee := tlsStore{root: t.TempDir()}
|
2022-09-28 11:29:01 -04:00
|
|
|
|
|
|
|
const contextName = "test-ctx"
|
|
|
|
|
2022-09-28 11:40:33 -04:00
|
|
|
_, err := testee.getData(contextName, "test-ep", "test-data")
|
2022-09-28 16:18:51 -04:00
|
|
|
assert.ErrorType(t, err, errdefs.IsNotFound)
|
2018-12-17 05:27:07 -05:00
|
|
|
|
2022-09-28 11:38:12 -04:00
|
|
|
err = testee.createOrUpdate(contextName, "test-ep", "test-data", []byte("data"))
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
2022-09-28 11:40:33 -04:00
|
|
|
data, err := testee.getData(contextName, "test-ep", "test-data")
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, string(data), "data")
|
2022-09-28 11:38:12 -04:00
|
|
|
err = testee.createOrUpdate(contextName, "test-ep", "test-data", []byte("data2"))
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
2022-09-28 11:40:33 -04:00
|
|
|
data, err = testee.getData(contextName, "test-ep", "test-data")
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, string(data), "data2")
|
|
|
|
|
2022-09-28 11:47:30 -04:00
|
|
|
err = testee.remove(contextName, "test-ep", "test-data")
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
2022-09-28 11:47:30 -04:00
|
|
|
err = testee.remove(contextName, "test-ep", "test-data")
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
2022-09-28 11:40:33 -04:00
|
|
|
_, err = testee.getData(contextName, "test-ep", "test-data")
|
2022-09-28 16:18:51 -04:00
|
|
|
assert.ErrorType(t, err, errdefs.IsNotFound)
|
2018-12-17 05:27:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTlsListAndBatchRemove(t *testing.T) {
|
2022-02-25 08:37:07 -05:00
|
|
|
testee := tlsStore{root: t.TempDir()}
|
2018-12-17 05:27:07 -05:00
|
|
|
|
|
|
|
all := map[string]EndpointFiles{
|
|
|
|
"ep1": {"f1", "f2", "f3"},
|
|
|
|
"ep2": {"f1", "f2", "f3"},
|
|
|
|
"ep3": {"f1", "f2", "f3"},
|
|
|
|
}
|
|
|
|
|
|
|
|
ep1ep2 := map[string]EndpointFiles{
|
|
|
|
"ep1": {"f1", "f2", "f3"},
|
|
|
|
"ep2": {"f1", "f2", "f3"},
|
|
|
|
}
|
|
|
|
|
2022-09-28 11:21:01 -04:00
|
|
|
const contextName = "test-ctx"
|
2018-12-17 05:27:07 -05:00
|
|
|
for name, files := range all {
|
|
|
|
for _, file := range files {
|
2022-09-28 11:38:12 -04:00
|
|
|
err := testee.createOrUpdate(contextName, name, file, []byte("data"))
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-28 11:51:25 -04:00
|
|
|
resAll, err := testee.listContextData(contextName)
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, resAll, all)
|
|
|
|
|
2022-09-28 11:36:21 -04:00
|
|
|
err = testee.removeAllEndpointData(contextName, "ep3")
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
2022-09-28 11:51:25 -04:00
|
|
|
resEp1ep2, err := testee.listContextData(contextName)
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, resEp1ep2, ep1ep2)
|
|
|
|
|
2022-09-28 11:21:01 -04:00
|
|
|
err = testee.removeAllContextData(contextName)
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
2022-09-28 11:51:25 -04:00
|
|
|
resEmpty, err := testee.listContextData(contextName)
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, resEmpty, map[string]EndpointFiles{})
|
|
|
|
}
|