MCPcopy Index your code
hub / github.com/netdata/netdata / TestFetchTableColumns

Function TestFetchTableColumns

src/go/plugin/go.d/pkg/sqlquery/columns_test.go:16–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestFetchTableColumns(t *testing.T) {
17 t.Run("without transform", func(t *testing.T) {
18 db, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual))
19 require.NoError(t, err)
20 defer func() { _ = db.Close() }()
21
22 query, err := tableColumnsQuery(PlaceholderQuestion)
23 require.NoError(t, err)
24 mock.ExpectQuery(query).
25 WithArgs("performance_schema", "events_statements_summary_by_digest").
26 WillReturnRows(sqlmock.NewRows([]string{"COLUMN_NAME"}).
27 AddRow("DIGEST").
28 AddRow("COUNT_STAR"))
29
30 cols, err := FetchTableColumns(
31 context.Background(),
32 db,
33 "performance_schema",
34 "events_statements_summary_by_digest",
35 PlaceholderQuestion,
36 nil,
37 )
38 require.NoError(t, err)
39 assert.Equal(t, map[string]bool{
40 "DIGEST": true,
41 "COUNT_STAR": true,
42 }, cols)
43 assert.NoError(t, mock.ExpectationsWereMet())
44 })
45
46 t.Run("with transform", func(t *testing.T) {
47 db, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual))
48 require.NoError(t, err)
49 defer func() { _ = db.Close() }()
50
51 query, err := tableColumnsQuery(PlaceholderQuestion)
52 require.NoError(t, err)
53 mock.ExpectQuery(query).
54 WithArgs("performance_schema", "events_statements_history_long").
55 WillReturnRows(sqlmock.NewRows([]string{"COLUMN_NAME"}).
56 AddRow("digest").
57 AddRow("mysql_errno"))
58
59 cols, err := FetchTableColumns(
60 context.Background(),
61 db,
62 "performance_schema",
63 "events_statements_history_long",
64 PlaceholderQuestion,
65 strings.ToUpper,
66 )
67 require.NoError(t, err)
68 assert.Equal(t, map[string]bool{
69 "DIGEST": true,
70 "MYSQL_ERRNO": true,
71 }, cols)
72 assert.NoError(t, mock.ExpectationsWereMet())
73 })

Callers

nothing calls this directly

Calls 9

tableColumnsQueryFunction · 0.85
FetchTableColumnsFunction · 0.85
PlaceholderStyleTypeAlias · 0.85
EqualMethod · 0.80
RunMethod · 0.65
NewMethod · 0.65
CloseMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…