Skip to content

Commit 6864035

Browse files
committed
fix lint
1 parent ed86e5e commit 6864035

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

internal/services/cockpit/alert_manager.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,11 @@ func ResourceCockpitAlertManagerRead(ctx context.Context, d *schema.ResourceData
125125
}
126126

127127
// Parse the ID to get projectID
128-
parsedRegion, projectID, err := ResourceCockpitAlertManagerParseID(d.Id())
128+
_, projectID, err := ResourceCockpitAlertManagerParseID(d.Id())
129129
if err != nil {
130130
return diag.FromErr(err)
131131
}
132132

133-
// Use the parsed region instead of the one from the schema
134-
region = parsedRegion
135-
136133
alertManager, err := api.GetAlertManager(&cockpit.RegionalAPIGetAlertManagerRequest{
137134
Region: region,
138135
ProjectID: projectID,
@@ -177,14 +174,11 @@ func ResourceCockpitAlertManagerUpdate(ctx context.Context, d *schema.ResourceDa
177174
}
178175

179176
// Parse the ID to get projectID
180-
parsedRegion, projectID, err := ResourceCockpitAlertManagerParseID(d.Id())
177+
_, projectID, err := ResourceCockpitAlertManagerParseID(d.Id())
181178
if err != nil {
182179
return diag.FromErr(err)
183180
}
184181

185-
// Use the parsed region instead of the one from the schema
186-
region = parsedRegion
187-
188182
if d.HasChange("enable_managed_alerts") {
189183
enable := d.Get("enable_managed_alerts").(bool)
190184
if enable {
@@ -264,14 +258,11 @@ func ResourceCockpitAlertManagerDelete(ctx context.Context, d *schema.ResourceDa
264258
}
265259

266260
// Parse the ID to get projectID
267-
parsedRegion, projectID, err := ResourceCockpitAlertManagerParseID(d.Id())
261+
_, projectID, err := ResourceCockpitAlertManagerParseID(d.Id())
268262
if err != nil {
269263
return diag.FromErr(err)
270264
}
271265

272-
// Use the parsed region instead of the one from the schema
273-
region = parsedRegion
274-
275266
contactPoints, err := api.ListContactPoints(&cockpit.RegionalAPIListContactPointsRequest{
276267
Region: region,
277268
ProjectID: projectID,

internal/services/cockpit/alert_manager_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cockpit_test
22

33
import (
4+
"errors"
45
"fmt"
56
"strings"
67
"testing"
@@ -267,7 +268,7 @@ func testAccCheckAlertManagerEnabled(tt *acctest.TestTools, resourceName string,
267268
return func(s *terraform.State) error {
268269
rs, ok := s.RootModule().Resources[resourceName]
269270
if !ok {
270-
return fmt.Errorf("alert manager not found: %s", resourceName)
271+
return errors.New("alert manager not found: " + resourceName)
271272
}
272273

273274
api := cockpit.NewRegionalAPI(meta.ExtractScwClient(tt.Meta))
@@ -292,7 +293,7 @@ func testAccCheckCockpitContactPointExists(tt *acctest.TestTools, resourceName s
292293
return func(s *terraform.State) error {
293294
rs, ok := s.RootModule().Resources[resourceName]
294295
if !ok {
295-
return fmt.Errorf("alert manager not found: %s", resourceName)
296+
return errors.New("alert manager not found: " + resourceName)
296297
}
297298

298299
api := cockpit.NewRegionalAPI(meta.ExtractScwClient(tt.Meta))
@@ -311,7 +312,7 @@ func testAccCheckCockpitContactPointExists(tt *acctest.TestTools, resourceName s
311312
}
312313
}
313314

314-
return fmt.Errorf("contact point with email %s not found in project %s", rs.Primary.Attributes["emails.0"], projectID)
315+
return errors.New("contact point with email " + rs.Primary.Attributes["emails.0"] + " not found in project " + projectID)
315316
}
316317
}
317318

@@ -339,7 +340,7 @@ func testAccCockpitAlertManagerAndContactsDestroy(tt *acctest.TestTools) resourc
339340
}
340341

341342
if alertManager.AlertManagerEnabled {
342-
return fmt.Errorf("cockpit alert manager (%s) is still enabled", rs.Primary.ID)
343+
return errors.New("cockpit alert manager (" + rs.Primary.ID + ") is still enabled")
343344
}
344345
}
345346

@@ -352,42 +353,42 @@ func testAccCheckAlertManagerIDFormat(tt *acctest.TestTools, resourceName string
352353
return func(s *terraform.State) error {
353354
rs, ok := s.RootModule().Resources[resourceName]
354355
if !ok {
355-
return fmt.Errorf("alert manager not found: %s", resourceName)
356+
return errors.New("alert manager not found: " + resourceName)
356357
}
357358

358359
id := rs.Primary.ID
359360
if id == "" {
360-
return fmt.Errorf("alert manager ID is empty")
361+
return errors.New("alert manager ID is empty")
361362
}
362363

363364
parts := strings.Split(id, "/")
364365
if len(parts) != 3 {
365-
return fmt.Errorf("alert manager ID should have 3 parts, got %d: %s", len(parts), id)
366+
return errors.New("alert manager ID should have 3 parts, got " + fmt.Sprintf("%d", len(parts)) + ": " + id)
366367
}
367368

368369
region := parts[0]
369370
projectID := parts[1]
370371

371372
if region == "" {
372-
return fmt.Errorf("region part of ID is empty")
373+
return errors.New("region part of ID is empty")
373374
}
374375

375376
if projectID == "" {
376-
return fmt.Errorf("project ID part of ID is empty")
377+
return errors.New("project ID part of ID is empty")
377378
}
378379

379380
if parts[2] != "1" {
380-
return fmt.Errorf("third part of ID should be '1', got %s", parts[2])
381+
return errors.New("third part of ID should be '1', got " + parts[2])
381382
}
382383

383384
expectedProjectID := rs.Primary.Attributes["project_id"]
384385
if expectedProjectID != projectID {
385-
return fmt.Errorf("project_id in attributes (%s) doesn't match project_id in ID (%s)", expectedProjectID, projectID)
386+
return errors.New("project_id in attributes (" + expectedProjectID + ") doesn't match project_id in ID (" + projectID + ")")
386387
}
387388

388389
expectedRegion := rs.Primary.Attributes["region"]
389390
if expectedRegion != region {
390-
return fmt.Errorf("region in attributes (%s) doesn't match region in ID (%s)", expectedRegion, region)
391+
return errors.New("region in attributes (" + expectedRegion + ") doesn't match region in ID (" + region + ")")
391392
}
392393

393394
return nil

0 commit comments

Comments
 (0)