Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ECS client to aws-sdk-go-v2 #4447

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions ecs-agent/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ func ZeroOrNil(obj interface{}) bool {
return false
}

// Uint16SliceToStringPtrSlice converts a slice of type uint16 to a slice of type
// *string. It uses strconv.Itoa on each element
func Uint16SliceToStringPtrSlice(slice []uint16) []*string {
stringSlice := make([]*string, len(slice))
for i, el := range slice {
str := strconv.Itoa(int(el))
stringSlice[i] = &str
}
return stringSlice
}

// Uint16SliceToStringSlice converts a slice of type uint16 to a slice of type
// string. It uses strconv.Itoa on each element
func Uint16SliceToStringSlice(slice []uint16) []string {
Expand All @@ -64,12 +53,20 @@ func Uint16SliceToStringSlice(slice []uint16) []string {
return stringSlice
}

// Int64PtrToIntPtr converts a *int64 to *int.
func Int64PtrToIntPtr(int64ptr *int64) *int {
// Int32PtrToIntPtr converts a *int64 to *int.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Int32PtrToIntPtr converts a *int32 to *int.

func Int32PtrToIntPtr(int32ptr *int32) *int {
if int32ptr == nil {
return nil
}
return aws.Int(int(aws.Int32Value(int32ptr)))
}

// Int64PtrToInt32Ptr converts a *int64 to *int32.
func Int64PtrToInt32Ptr(int64ptr *int64) *int32 {
if int64ptr == nil {
return nil
}
return aws.Int(int(aws.Int64Value(int64ptr)))
return aws.Int32(int32(aws.Int64Value(int64ptr)))
}

// MaxNum returns the maximum value between two numbers.
Expand Down
16 changes: 4 additions & 12 deletions ecs-agent/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,28 @@ func TestUint16SliceToStringSlice(t *testing.T) {
stringSlice := Uint16SliceToStringSlice(tc.param)
assert.Equal(t, tc.expected, len(stringSlice), tc.name)

stringPtrSlice := Uint16SliceToStringPtrSlice(tc.param)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this unit test entirely, since the function Uint16SliceToStringPtrSlice is removed? And add a new unit test for the new Int64PtrToInt32Ptr method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will add it

assert.Equal(t, tc.expected, len(stringPtrSlice), tc.name)

for idx, num := range tc.param {
reconverted, err := strconv.Atoi(stringSlice[idx])
assert.NoError(t, err)
assert.Equal(t, num, uint16(reconverted))

assert.NotNil(t, stringPtrSlice[idx])
reconverted, err = strconv.Atoi(*stringPtrSlice[idx])
assert.NoError(t, err)
assert.Equal(t, num, uint16(reconverted))
}
})
}
}

func TestInt64PtrToIntPtr(t *testing.T) {
func TestInt32PtrToIntPtr(t *testing.T) {
testCases := []struct {
input *int64
input *int32
expectedOutput *int
name string
}{
{nil, nil, "nil"},
{aws.Int64(2147483647), aws.Int(2147483647), "smallest max value type int can hold"},
{aws.Int32(2147483647), aws.Int(2147483647), "smallest max value type int can hold"},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.expectedOutput, Int64PtrToIntPtr(tc.input))
assert.Equal(t, tc.expectedOutput, Int32PtrToIntPtr(tc.input))
})
}
}
Expand Down