Skip to content

Commit

Permalink
draft: test changes to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shmsr committed Jul 17, 2023
1 parent 063f8e2 commit 74ee9db
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
5 changes: 5 additions & 0 deletions x-pack/metricbeat/module/sql/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ services:
extends:
file: ../../../../x-pack/metricbeat/module/oracle/docker-compose.yml
service: oracle

mssql:
extends:
file: ../../../../x-pack/metricbeat/module/mssql/docker-compose.yml
service: mssql
Empty file.
Empty file.
64 changes: 56 additions & 8 deletions x-pack/metricbeat/module/sql/query/query_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/stretchr/testify/require"

// Drivers
_ "github.com/denisenkom/go-mssqldb"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"

Expand All @@ -27,6 +28,7 @@ import (
mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
"github.com/elastic/beats/v7/metricbeat/module/mysql"
"github.com/elastic/beats/v7/metricbeat/module/postgresql"
mssqltest "github.com/elastic/beats/v7/x-pack/metricbeat/module/mssql/testing"
)

type testFetchConfig struct {
Expand Down Expand Up @@ -79,6 +81,50 @@ func TestMySQL(t *testing.T) {
})
}

func TestMSSQL(t *testing.T) {
service := compose.EnsureUp(t, "mssql")
host, _, err := net.SplitHostPort(service.Host())
require.NoError(t, err)

conf := mssqltest.GetConfig(host)
cfg := testFetchConfig{
config: config{
Driver: "mssql",
Query: "",
ResponseFormat: tableResponseFormat,
RawData: rawData{Enabled: true},
},
Host: fmt.Sprintf("sqlserver://%s:%s@%s", conf["username"], conf["password"], host),
}

t.Run("fetch", func(t *testing.T) {
testFetch(t, cfg)
})

t.Run("data", func(t *testing.T) {
testData(t, cfg, "./_meta/data_mssql_tables.json")
})

cfg = testFetchConfig{
config: config{
Driver: "mssql",
Query: "",
ResponseFormat: tableResponseFormat,
RawData: rawData{Enabled: true},
FetchFromAllDbs: true,
},
Host: fmt.Sprintf("sqlserver://%s:%s@%s", conf["username"], conf["password"], host),
}

t.Run("fetch", func(t *testing.T) {
testFetch(t, cfg)
})

t.Run("data", func(t *testing.T) {
testData(t, cfg, "./_meta/data_mssql_tables_fetch_from_all_dbs.json")
})
}

func TestPostgreSQL(t *testing.T) {
service := compose.EnsureUp(t, "postgresql")
host, port, err := net.SplitHostPort(service.Host())
Expand Down Expand Up @@ -268,15 +314,17 @@ func testData(t *testing.T, cfg testFetchConfig, postfix string) {

func getConfig(cfg testFetchConfig) map[string]interface{} {
values := map[string]interface{}{
"module": "sql",
"metricsets": []string{"query"},
"hosts": []string{cfg.Host},
"driver": cfg.config.Driver,
"sql_query": cfg.config.Query,
"sql_queries": cfg.config.Queries,
"raw_data.enabled": cfg.config.RawData.Enabled,
"merge_results": cfg.config.MergeResults,
"module": "sql",
"metricsets": []string{"query"},
"hosts": []string{cfg.Host},
"driver": cfg.config.Driver,
"sql_query": cfg.config.Query,
"sql_queries": cfg.config.Queries,
"raw_data.enabled": cfg.config.RawData.Enabled,
"merge_results": cfg.config.MergeResults,
"fetch_from_all_dbs": cfg.config.FetchFromAllDbs,
}

if cfg.config.ResponseFormat != "" {
values["sql_response_format"] = cfg.config.ResponseFormat
}
Expand Down

0 comments on commit 74ee9db

Please sign in to comment.