Skip to content

Commit

Permalink
PMM-12913 fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Mar 22, 2024
1 parent b7a6094 commit 19e9759
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion managed/models/agent_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func AzureOptionsFromRequest(params AzureOptionsParams) *AzureOptions {
}

// Add a prefix since gRPC does not allow to pass an URL path segment that begins with a slash.
// TODO: Remove these Normalize... functions once we drop prefixes in agent/service/node IDs.
// TODO: remove these Normalize functions once we drop prefixes in agent/service/node IDs.

// NormalizeAgentID adds a prefix to the agent ID if it does not already contain it.
func NormalizeAgentID(agentID string) string {
Expand Down
8 changes: 4 additions & 4 deletions managed/services/inventory/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func TestAgents(t *testing.T) {
err := as.Remove(ctx, "/agent_id/00000000-0000-4000-8000-000000000005", true)
require.NoError(t, err)
actualAgent, err := as.Get(ctx, "/agent_id/00000000-0000-4000-8000-000000000005")
tests.AssertGRPCError(t, status.New(codes.NotFound, `Agent with ID "/agent_id/00000000-0000-4000-8000-000000000005" not found.`), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, `Agent with ID /agent_id/00000000-0000-4000-8000-000000000005 not found.`), err)
assert.Nil(t, actualAgent)

actualAgents, err = as.List(ctx, models.AgentFilters{})
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestAgents(t *testing.T) {
_, err := as.AddNodeExporter(ctx, &inventoryv1.AddNodeExporterParams{
PmmAgentId: "no-such-id",
})
tests.AssertGRPCError(t, status.New(codes.NotFound, `Agent with ID "no-such-id" not found.`), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, `Agent with ID no-such-id not found.`), err)
})

t.Run("AddRDSExporter", func(t *testing.T) {
Expand Down Expand Up @@ -474,15 +474,15 @@ func TestAgents(t *testing.T) {
PmmAgentId: pmmAgent.GetPmmAgent().AgentId,
ServiceId: "no-such-id",
})
tests.AssertGRPCError(t, status.New(codes.NotFound, `Service with ID "no-such-id" not found.`), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, `Service with ID no-such-id not found.`), err)
})

t.Run("RemoveNotFound", func(t *testing.T) {
_, as, _, teardown, ctx, _ := setup(t)
t.Cleanup(func() { teardown(t) })

err := as.Remove(ctx, "no-such-id", false)
tests.AssertGRPCError(t, status.New(codes.NotFound, `Agent with ID "no-such-id" not found.`), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, `Agent with ID no-such-id not found.`), err)
})

t.Run("PushMetricsMongodbExporter", func(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions managed/services/inventory/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ func TestServices(t *testing.T) {
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Service with ID "%s" not found.`, mySQLService.ServiceId)), err)

_, err = as.Get(ctx, rdsAgent.GetRdsExporter().AgentId)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, rdsAgent.GetRdsExporter().AgentId)), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID %s not found.`, rdsAgent.GetRdsExporter().AgentId)), err)

_, err = as.Get(ctx, mySQLAgent.GetMysqldExporter().AgentId)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, mySQLAgent.GetMysqldExporter().AgentId)), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID %s not found.`, mySQLAgent.GetMysqldExporter().AgentId)), err)

_, err = ns.Get(ctx, &inventoryv1.GetNodeRequest{NodeId: node.NodeId})
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Node with ID "%s" not found.`, node.NodeId)), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Node with ID %s not found.`, node.NodeId)), err)
})

t.Run("AzureServiceRemoving", func(t *testing.T) {
Expand Down Expand Up @@ -244,10 +244,10 @@ func TestServices(t *testing.T) {
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Service with ID "%s" not found.`, mySQLService.ServiceId)), err)

_, err = as.Get(ctx, azureAgent.GetAzureDatabaseExporter().AgentId)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, azureAgent.GetAzureDatabaseExporter().AgentId)), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID %s not found.`, azureAgent.GetAzureDatabaseExporter().AgentId)), err)

_, err = as.Get(ctx, mySQLAgent.GetMysqldExporter().AgentId)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, mySQLAgent.GetMysqldExporter().AgentId)), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID %s not found.`, mySQLAgent.GetMysqldExporter().AgentId)), err)

_, err = ns.Get(ctx, &inventoryv1.GetNodeRequest{NodeId: node.NodeId})
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Node with ID "%s" not found.`, node.NodeId)), err)
Expand Down
10 changes: 5 additions & 5 deletions managed/services/management/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestServiceService(t *testing.T) {

agent, err := models.FindAgentByID(s.db.Querier, mysqldExporter.AgentID)
assert.Nil(t, agent)
tests.AssertGRPCError(t, status.New(codes.NotFound, `Agent with ID "/agent_id/00000000-0000-4000-8000-000000000007" not found.`), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, `Agent with ID /agent_id/00000000-0000-4000-8000-000000000007 not found.`), err)

service, err = models.FindServiceByID(s.db.Querier, service.ServiceID)
assert.Nil(t, service)
Expand Down Expand Up @@ -214,10 +214,10 @@ func TestServiceService(t *testing.T) {
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Service with ID "%s" not found.`, service.ServiceID)), err)

_, err = models.FindAgentByID(s.db.Querier, mysqldExporter.AgentID)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, mysqldExporter.AgentID)), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID %s not found.`, mysqldExporter.AgentID)), err)

_, err = models.FindAgentByID(s.db.Querier, rdsExporter.AgentID)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, rdsExporter.AgentID)), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID %s not found.`, rdsExporter.AgentID)), err)

_, err = models.FindNodeByID(s.db.Querier, node.NodeID)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Node with ID "%s" not found.`, node.NodeID)), err)
Expand Down Expand Up @@ -268,10 +268,10 @@ func TestServiceService(t *testing.T) {
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Service with ID "%s" not found.`, service.ServiceID)), err)

_, err = models.FindAgentByID(s.db.Querier, mysqldExporter.AgentID)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, mysqldExporter.AgentID)), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID %s not found.`, mysqldExporter.AgentID)), err)

_, err = models.FindAgentByID(s.db.Querier, azureExporter.AgentID)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID "%s" not found.`, azureExporter.AgentID)), err)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Agent with ID %s not found.`, azureExporter.AgentID)), err)

_, err = models.FindNodeByID(s.db.Querier, node.NodeID)
tests.AssertGRPCError(t, status.New(codes.NotFound, fmt.Sprintf(`Node with ID "%s" not found.`, node.NodeID)), err)
Expand Down

0 comments on commit 19e9759

Please sign in to comment.