-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51b2fab
commit 7df6d62
Showing
4 changed files
with
65 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 11 additions & 8 deletions
19
src/metrics/io_test.go → src/metrics/sinks/postgres_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
package metrics_test | ||
package sinks_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/cybertec-postgresql/pgwatch3/metrics" | ||
"github.com/cybertec-postgresql/pgwatch3/metrics/sinks" | ||
"github.com/pashagolub/pgxmock/v3" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ctx = context.Background() | ||
|
||
func TestGetMetricSchemaType(t *testing.T) { | ||
func TestReadMetricSchemaType(t *testing.T) { | ||
conn, err := pgxmock.NewPool() | ||
assert.NoError(t, err) | ||
|
||
pgw := sinks.PostgresWriter{ | ||
Ctx: ctx, | ||
SinkDb: conn, | ||
} | ||
|
||
conn.ExpectQuery("SELECT schema_type"). | ||
WillReturnError(errors.New("expected")) | ||
_, err = metrics.GetMetricSchemaType(ctx, conn) | ||
assert.Error(t, err) | ||
assert.Error(t, pgw.ReadMetricSchemaType()) | ||
|
||
conn.ExpectQuery("SELECT schema_type"). | ||
WillReturnRows(pgxmock.NewRows([]string{"schema_type"}).AddRow(true)) | ||
schemaType, err := metrics.GetMetricSchemaType(context.Background(), conn) | ||
assert.NoError(t, err) | ||
assert.Equal(t, metrics.MetricSchemaTimescale, schemaType) | ||
assert.NoError(t, pgw.ReadMetricSchemaType()) | ||
assert.Equal(t, sinks.DbStorageSchemaTimescale, pgw.MetricSchema) | ||
} |