Skip to content

Commit

Permalink
fix: use Split instead of SplitN
Browse files Browse the repository at this point in the history
  • Loading branch information
VAveryanov8 committed Dec 17, 2024
1 parent c9f5e9a commit 18feedb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/cloudmeta/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (gcp *gcpMetadata) getMachineType(ctx context.Context) (string, error) {
func parseMachineTypeResponse(resp string) (string, error) {
errUnexpectedFormat := errors.Errorf("unexpected machineType response format: %s", resp)

parts := strings.SplitN(resp, "/", 4)
parts := strings.Split(resp, "/")
if len(parts) != 4 {
return "", errUnexpectedFormat
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/cloudmeta/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func TestParseMachineTypeResponse(t *testing.T) {
expectedErr: true,
expected: "",
},
{
name: "new response part is added after machineTypes part",
machineTypeResponse: "projects/project1/machineTypes/machineType1/zones/zone1",

expectedErr: true,
expected: "",
},
{
name: "parts are mixed up",
machineTypeResponse: "machineTypes/machineType1/projects/project1",
Expand Down

0 comments on commit 18feedb

Please sign in to comment.