-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More gracevully reject colonCompoundIDs that aren't compound IDs
Avoids an array out of bounds (panic) resulting from colon compound resource IDs that have only one component (no colon).
- Loading branch information
1 parent
6f39184
commit 4f90ecf
Showing
10 changed files
with
121 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestResourcePagerDutyParseColonCompoundID(t *testing.T) { | ||
resourceIDComponents := []string{"PABC12A", "PABC12B"} | ||
validCompoundResourceID := strings.Join(resourceIDComponents, ":") | ||
|
||
first, second, err := resourcePagerDutyParseColonCompoundID(validCompoundResourceID) | ||
|
||
if err != nil { | ||
t.Fatalf("%s: expected success while parsing invalid compound resource id: got %s", validCompoundResourceID, err) | ||
} | ||
|
||
for i, component := range []string{first, second} { | ||
expectedResourceIDComponent := resourceIDComponents[i] | ||
|
||
if expectedResourceIDComponent != component { | ||
t.Errorf( | ||
"%s: expected component %d of a valid compound resource ID to be %s: got %s", | ||
validCompoundResourceID, | ||
i+1, | ||
expectedResourceIDComponent, | ||
component, | ||
) | ||
} | ||
} | ||
} | ||
|
||
func TestResourcePagerDutyParseColonCompoundIDFailsForInvalidCompoundIDs(t *testing.T) { | ||
invalidCompoundResourceID := "PABC12APABC12B" | ||
|
||
_, _, err := resourcePagerDutyParseColonCompoundID(invalidCompoundResourceID) | ||
|
||
if err == nil { | ||
t.Fatalf("%s: expected errors while parsing invalid compound resource id: got success", invalidCompoundResourceID) | ||
} | ||
} |