From 08aba6cd510a36b4335c9b11ae60a983b1d94caa Mon Sep 17 00:00:00 2001 From: TwiN Date: Thu, 4 Nov 2021 21:40:05 -0400 Subject: [PATCH] Minor updates --- README.md | 17 +++++++++++------ storage/store/sql/sql_test.go | 6 +++--- storage/store/store_test.go | 14 +++++++------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0c767af1..328b3bc0 100644 --- a/README.md +++ b/README.md @@ -235,12 +235,17 @@ Here are some examples of conditions you can use: | Parameter | Description | Default | |:------------------ |:-------------------------------------------------------------------------------------- |:-------------- | | `storage` | Storage configuration | `{}` | -| `storage.file` | Path to persist the data in. If the type is `memory`, data is persisted on interval. | `""` | -| `storage.type` | Type of storage. Valid types: `memory`, `sqlite`, `postgres` (ALPHA). | `"memory"` | +| `storage.path` | Path to persist the data in. Only supported for types `sqlite` and `postgres`. | `""` | +| `storage.type` | Type of storage. Valid types: `memory`, `sqlite`, `postgres`. | `"memory"` | -- If `storage.type` is `memory` (default) and `storage.file` is set to a non-blank value. - Furthermore, the data is periodically persisted, but everything remains in memory. -- If `storage.type` is `sqlite`, `storage.file` must not be blank: +- If `storage.type` is `memory` (default): +```yaml +# Note that this is the default value, and you can omit the storage configuration altogether to achieve the same result. +# Because the data is stored in memory, the data will not survive a restart. +storage: + type: memory +``` +- If `storage.type` is `sqlite`, `storage.path` must not be blank: ```yaml storage: type: sqlite @@ -248,7 +253,7 @@ storage: ``` See [examples/docker-compose-sqlite-storage](.examples/docker-compose-sqlite-storage) for an example. -- If `storage.type` is `postgres`, `storage.file` must be the connection URL: +- If `storage.type` is `postgres`, `storage.path` must be the connection URL: ```yaml storage: type: postgres diff --git a/storage/store/sql/sql_test.go b/storage/store/sql/sql_test.go index 0389e883..9eaf94e2 100644 --- a/storage/store/sql/sql_test.go +++ b/storage/store/sql/sql_test.go @@ -169,8 +169,8 @@ func TestStore_InsertCleansUpEventsAndResultsProperly(t *testing.T) { } func TestStore_Persistence(t *testing.T) { - file := t.TempDir() + "/TestStore_Persistence.db" - store, _ := NewStore("sqlite", file) + path := t.TempDir() + "/TestStore_Persistence.db" + store, _ := NewStore("sqlite", path) store.Insert(&testEndpoint, &testSuccessfulResult) store.Insert(&testEndpoint, &testUnsuccessfulResult) if uptime, _ := store.GetUptimeByKey(testEndpoint.Key(), time.Now().Add(-time.Hour), time.Now()); uptime != 0.5 { @@ -188,7 +188,7 @@ func TestStore_Persistence(t *testing.T) { t.Fatal("sanity check failed") } store.Close() - store, _ = NewStore("sqlite", file) + store, _ = NewStore("sqlite", path) defer store.Close() ssFromNewStore, _ := store.GetEndpointStatus(testEndpoint.Group, testEndpoint.Name, paging.NewEndpointStatusParams().WithResults(1, common.MaximumNumberOfResults).WithEvents(1, common.MaximumNumberOfEvents)) if ssFromNewStore == nil || ssFromNewStore.Group != "group" || ssFromNewStore.Name != "name" || len(ssFromNewStore.Events) != 3 || len(ssFromNewStore.Results) != 2 { diff --git a/storage/store/store_test.go b/storage/store/store_test.go index da0d959f..6bfe24c5 100644 --- a/storage/store/store_test.go +++ b/storage/store/store_test.go @@ -547,23 +547,23 @@ func TestInitialize(t *testing.T) { ExpectedErr: nil, }, { - Name: "memory-no-file", + Name: "memory-no-path", Cfg: &storage.Config{Type: storage.TypeMemory}, ExpectedErr: nil, }, - { - Name: "memory-with-file", - Cfg: &storage.Config{Type: storage.TypeMemory, Path: t.TempDir() + "/TestInitialize_memory-with-file.db"}, + { // XXX: Remove for v4.0.0. See https://github.com/TwiN/gatus/issues/198 + Name: "memory-with-path", + Cfg: &storage.Config{Type: storage.TypeMemory, Path: t.TempDir() + "/TestInitialize_memory-with-path.db"}, ExpectedErr: nil, }, { - Name: "sqlite-no-file", + Name: "sqlite-no-path", Cfg: &storage.Config{Type: storage.TypeSQLite}, ExpectedErr: sql.ErrPathNotSpecified, }, { - Name: "sqlite-with-file", - Cfg: &storage.Config{Type: storage.TypeSQLite, Path: t.TempDir() + "/TestInitialize_sqlite-with-file.db"}, + Name: "sqlite-with-path", + Cfg: &storage.Config{Type: storage.TypeSQLite, Path: t.TempDir() + "/TestInitialize_sqlite-with-path.db"}, ExpectedErr: nil, }, }