Skip to content

Commit

Permalink
PMM-12913 fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Mar 22, 2024
1 parent 1171eb8 commit c2bb30f
Show file tree
Hide file tree
Showing 33 changed files with 7,383 additions and 7,494 deletions.
14 changes: 5 additions & 9 deletions admin/commands/inventory/list_agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,12 @@ func (cmd *ListAgentsCommand) RunCmd() (commands.Result, error) {
return nil, err
}

filters := agents.ListAgentsBody{
PMMAgentID: cmd.PMMAgentID,
ServiceID: cmd.ServiceID,
NodeID: cmd.NodeID,
AgentType: agentType,
}

params := &agents.ListAgentsParams{
Body: filters,
Context: commands.Ctx,
PMMAgentID: pointer.ToString(cmd.PMMAgentID),
ServiceID: pointer.ToString(cmd.ServiceID),
NodeID: pointer.ToString(cmd.NodeID),
AgentType: agentType,
Context: commands.Ctx,
}
agentsRes, err := client.Default.AgentsService.ListAgents(params)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions api-tests/inventory/agents_azure_database_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestAzureDatabaseExporter(t *testing.T) { //nolint:tparallel
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestAzureDatabaseExporter(t *testing.T) { //nolint:tparallel
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions api-tests/inventory/agents_external_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestExternalExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestExternalExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -377,7 +377,7 @@ func TestExternalExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions api-tests/inventory/agents_mongodb_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestMongoDBExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestMongoDBExporter(t *testing.T) {

getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions api-tests/inventory/agents_mysqld_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestMySQLdExporter(t *testing.T) {

getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -389,7 +389,7 @@ func TestMySQLdExporter(t *testing.T) {

getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions api-tests/inventory/agents_node_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestNodeExporter(t *testing.T) {

getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestNodeExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions api-tests/inventory/agents_postgres_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestPostgresExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestPostgresExporter(t *testing.T) {

getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions api-tests/inventory/agents_proxysql_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestProxySQLExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestProxySQLExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions api-tests/inventory/agents_rds_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestRDSExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestRDSExporter(t *testing.T) {

getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down
51 changes: 23 additions & 28 deletions api-tests/inventory/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
services "github.com/percona/pmm/api/inventory/v1/json/client/services_service"
"github.com/percona/pmm/api/inventory/v1/types"
)

// AgentStatusUnknown means agent is not connected and we don't know anything about its status.
Expand Down Expand Up @@ -143,8 +144,8 @@ func TestAgents(t *testing.T) {
// Filter by pmm agent ID.
res, err := client.Default.AgentsService.ListAgents(
&agents.ListAgentsParams{
Body: agents.ListAgentsBody{PMMAgentID: pmmAgentID},
Context: pmmapitests.Context,
PMMAgentID: pointer.ToString(pmmAgentID),
Context: pmmapitests.Context,
})
require.NoError(t, err)
require.NotNil(t, res)
Expand All @@ -156,7 +157,7 @@ func TestAgents(t *testing.T) {
// Filter by node ID.
res, err = client.Default.AgentsService.ListAgents(
&agents.ListAgentsParams{
Body: agents.ListAgentsBody{NodeID: nodeID},
NodeID: pointer.ToString(nodeID),
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand All @@ -169,8 +170,8 @@ func TestAgents(t *testing.T) {
// Filter by service ID.
res, err = client.Default.AgentsService.ListAgents(
&agents.ListAgentsParams{
Body: agents.ListAgentsBody{ServiceID: serviceID},
Context: pmmapitests.Context,
ServiceID: pointer.ToString(serviceID),
Context: pmmapitests.Context,
})
require.NoError(t, err)
require.NotNil(t, res)
Expand All @@ -182,8 +183,8 @@ func TestAgents(t *testing.T) {
// Filter by service ID.
res, err = client.Default.AgentsService.ListAgents(
&agents.ListAgentsParams{
Body: agents.ListAgentsBody{AgentType: pointer.ToString(agents.ListAgentsBodyAgentTypeAGENTTYPEMYSQLDEXPORTER)},
Context: pmmapitests.Context,
AgentType: pointer.ToString(types.AgentTypeMySQLdExporter),
Context: pmmapitests.Context,
})
require.NoError(t, err)
require.NotNil(t, res)
Expand All @@ -206,12 +207,10 @@ func TestAgents(t *testing.T) {

res, err := client.Default.AgentsService.ListAgents(
&agents.ListAgentsParams{
Body: agents.ListAgentsBody{
PMMAgentID: pmmAgentID,
NodeID: genericNodeID,
ServiceID: "some-service-id",
},
Context: pmmapitests.Context,
PMMAgentID: pointer.ToString(pmmAgentID),
NodeID: pointer.ToString(genericNodeID),
ServiceID: pointer.ToString("some-service-id"),
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "expected at most one param: pmm_agent_id, node_id or service_id")
assert.Nil(t, res)
Expand Down Expand Up @@ -270,7 +269,7 @@ func TestPMMAgent(t *testing.T) {

getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
assert.NoError(t, err)
Expand Down Expand Up @@ -366,7 +365,7 @@ func TestPMMAgent(t *testing.T) {
// Check that agents aren't removed.
getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: pmmAgentID},
AgentID: pmmAgentID,
Context: pmmapitests.Context,
})
assert.NoError(t, err)
Expand All @@ -382,10 +381,8 @@ func TestPMMAgent(t *testing.T) {

listAgentsOK, err := client.Default.AgentsService.ListAgents(
&agents.ListAgentsParams{
Body: agents.ListAgentsBody{
PMMAgentID: pmmAgentID,
},
Context: pmmapitests.Context,
PMMAgentID: pointer.ToString(pmmAgentID),
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.Equal(t, []*agents.ListAgentsOKBodyNodeExporterItems0{
Expand Down Expand Up @@ -429,17 +426,15 @@ func TestPMMAgent(t *testing.T) {
// Check that agents are removed.
getAgentRes, err = client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: pmmAgentID},
AgentID: pmmAgentID,
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, "Agent with ID %q not found.", pmmAgentID)
assert.Nil(t, getAgentRes)

listAgentsOK, err = client.Default.AgentsService.ListAgents(&agents.ListAgentsParams{
Body: agents.ListAgentsBody{
PMMAgentID: pmmAgentID,
},
Context: pmmapitests.Context,
PMMAgentID: pointer.ToString(pmmAgentID),
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, "Agent with ID %q not found.", pmmAgentID)
assert.Nil(t, listAgentsOK)
Expand Down Expand Up @@ -532,7 +527,7 @@ func TestQanAgentExporter(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -791,7 +786,7 @@ func TestPGStatStatementsQanAgent(t *testing.T) {

getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -1049,7 +1044,7 @@ func TestPGStatMonitorQanAgent(t *testing.T) {
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.AgentsService.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down Expand Up @@ -1177,7 +1172,7 @@ func TestPGStatMonitorQanAgent(t *testing.T) {

getAgentRes, err := client.Default.AgentsService.GetAgent(
&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
AgentID: agentID,
Context: pmmapitests.Context,
})
require.NoError(t, err)
Expand Down
4 changes: 1 addition & 3 deletions api-tests/inventory/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,7 @@ func TestRemoveNode(t *testing.T) {
assert.Nil(t, getServiceResp)

listAgentsOK, err := client.Default.AgentsService.ListAgents(&agents.ListAgentsParams{
Body: agents.ListAgentsBody{
NodeID: node.Generic.NodeID,
},
NodeID: pointer.ToString(node.Generic.NodeID),
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, "Node with ID %q not found.", node.Generic.NodeID)
Expand Down
6 changes: 2 additions & 4 deletions api-tests/inventory/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,8 @@ func TestRemoveService(t *testing.T) {
assert.Nil(t, getServiceResp)

listAgentsOK, err := client.Default.AgentsService.ListAgents(&agents.ListAgentsParams{
Body: agents.ListAgentsBody{
ServiceID: serviceID,
},
Context: pmmapitests.Context,
ServiceID: pointer.ToString(serviceID),
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, "Service with ID %q not found.", serviceID)
assert.Nil(t, listAgentsOK)
Expand Down
Loading

0 comments on commit c2bb30f

Please sign in to comment.