diff --git a/build.sh b/build.sh index c1728e6..55bb190 100755 --- a/build.sh +++ b/build.sh @@ -53,7 +53,8 @@ BINARY_NAME="aquarium-fish-$git_version" echo echo "--- RUN UNIT TESTS ---" -go test -ldflags="$version_flags" -v ./lib/... +# Unit tests should not consume more then 5 sec per run - for that we have integration tests +go test -timeout=5s -ldflags="$version_flags" -v ./lib/... echo echo "--- BUILD ${BINARY_NAME} ($MAXJOBS in parallel) ---" diff --git a/lib/drivers/aws/util.go b/lib/drivers/aws/util.go index 4db5e13..6c63d87 100644 --- a/lib/drivers/aws/util.go +++ b/lib/drivers/aws/util.go @@ -717,7 +717,7 @@ func (d *Driver) deleteImage(conn *ec2.Client, id string) (err error) { func awsLastYearFilterValues(till time.Time) (out []string) { date := till // Iterating over months to cover the last year - for date.Year() == till.Year() || date.Month() >= till.Month() { + for date.Year() == till.Year() || date.Month() > till.Month() { out = append(out, date.Format("2006-01-*")) date = date.AddDate(0, -1, 0) } diff --git a/lib/drivers/aws/util_test.go b/lib/drivers/aws/util_test.go new file mode 100644 index 0000000..dbbfe0e --- /dev/null +++ b/lib/drivers/aws/util_test.go @@ -0,0 +1,38 @@ +/** + * Copyright 2024 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package aws + +import ( + "fmt" + "testing" + "time" +) + +// Make sure there is no more issues in a simple logic of awsLastYearFilterValues like the Jan bug +func Test_awsLastYearFilterValues(t *testing.T) { + // Next 100 years should be enough to be sure + imagesTill := time.Now() + endyear := imagesTill.AddDate(100, 0, 0).Year() + for imagesTill.Year() < endyear { + curryear := imagesTill.Year() + t.Run(fmt.Sprintf("Testing year `%d`", curryear), func(t *testing.T) { + for imagesTill.Year() == curryear { + imagesTill = imagesTill.AddDate(0, 1, 0) + out := awsLastYearFilterValues(imagesTill) + if len(out) != 12 { + t.Fatalf("awsLastYearFilterValues(`%s`) = `%s` (len = %d); want: 12 values", imagesTill.Format("2006-01"), out, len(out)) + } + } + }) + } +}