2018-12-17 05:27:07 -05:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
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"
|
|
|
|
contextID := contextdirOf(contextName)
|
|
|
|
|
|
|
|
_, err := testee.getData(contextID, "test-ep", "test-data")
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.Equal(t, true, IsErrTLSDataDoesNotExist(err))
|
|
|
|
|
2022-09-28 11:29:01 -04:00
|
|
|
err = testee.createOrUpdate(contextID, "test-ep", "test-data", []byte("data"))
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
2022-09-28 11:29:01 -04:00
|
|
|
data, err := testee.getData(contextID, "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:29:01 -04:00
|
|
|
err = testee.createOrUpdate(contextID, "test-ep", "test-data", []byte("data2"))
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
2022-09-28 11:29:01 -04:00
|
|
|
data, err = testee.getData(contextID, "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:29:01 -04:00
|
|
|
err = testee.remove(contextID, "test-ep", "test-data")
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
2022-09-28 11:29:01 -04:00
|
|
|
err = testee.remove(contextID, "test-ep", "test-data")
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
2022-09-28 11:29:01 -04:00
|
|
|
_, err = testee.getData(contextID, "test-ep", "test-data")
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.Equal(t, true, IsErrTLSDataDoesNotExist(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
contextID := contextdirOf(contextName)
|
2018-12-17 05:27:07 -05:00
|
|
|
for name, files := range all {
|
|
|
|
for _, file := range files {
|
2022-09-28 11:21:01 -04:00
|
|
|
err := testee.createOrUpdate(contextID, name, file, []byte("data"))
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-28 11:21:01 -04:00
|
|
|
resAll, err := testee.listContextData(contextID)
|
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:21:01 -04:00
|
|
|
resEp1ep2, err := testee.listContextData(contextID)
|
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:21:01 -04:00
|
|
|
resEmpty, err := testee.listContextData(contextID)
|
2018-12-17 05:27:07 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, resEmpty, map[string]EndpointFiles{})
|
|
|
|
}
|