Skip to content

Commit

Permalink
ci: removed upload step
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-cardenas-coding committed Nov 26, 2023
1 parent ca3ecc7 commit aa0d825
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 74 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,4 @@ jobs:
run: |
echo "--------------------------------------------------"
go build -ldflags="-X 'github.com/karl-cardenas-coding/go-lambda-cleanup/cmd.VersionString=0.0.0'" -o=glc -v
./glc clean -r us-west-2
- uses: actions/upload-artifact@v1
with:
name: test-results
path: go.txt
./glc clean -r us-west-2
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tests: ## Run tests

tests-coverage: ## Start Go Test with code coverage
@echo "Running Go Tests with code coverage"
go test -race -cover -coverprofile=coverage.out ./...
go test -race -shuffle on -cover -coverprofile=coverage.out ./...

view-coverage: ## View the code coverage
@echo "Viewing the code coverage"
Expand Down
177 changes: 110 additions & 67 deletions cmd/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func TestCalculateFileSize(t *testing.T) {
if got2 != want2 {
t.Fatalf("Expected the size output to be %s but received %s instead", want2, got2)
}

}

func TestDisplayDuration(t *testing.T) {
Expand Down Expand Up @@ -411,6 +412,22 @@ func TestDeleteLambdaVersionError(t *testing.T) {
t.Errorf("expected an error to be returned but received %v", err)
}

t.Cleanup(func() {
GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(0),
}

})

}

func TestDeleteLambdaVersion(t *testing.T) {
Expand Down Expand Up @@ -453,7 +470,7 @@ func TestDeleteLambdaVersion(t *testing.T) {
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(2),
Retain: aws.Int8(0),
}

bf, err := getZipPackage("../tests/handler.zip")
Expand Down Expand Up @@ -496,71 +513,80 @@ func TestDeleteLambdaVersion(t *testing.T) {
t.Errorf("expected 2 functions to be returned but received %v", result)
}

t.Cleanup(func() {
GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(0),
}

})

}

func TestAWSEnteryMissingEnvRegion(t *testing.T) {

GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(2),
}

expectedErr := "Missing region flag and AWS_DEFAULT_REGION env variable. Please use -r and provide a valid AWS region"

err := CleanCmd.RunE(CleanCmd, []string{"--profile", "default", "--retain", "2", "--dry-run"})
if err == nil && err.Error() != expectedErr {
t.Fatalf("Expected an error to be returned but received %v", err.Error())
}

t.Cleanup(func() {
GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(2),
}

})

}

func TestAWSValidateRegion(t *testing.T) {

GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(2),
}

input := "us-east-1"
want := "us-east-1"
got, err := validateRegion(rr, input)
if err != nil || got != want {
t.Fatalf("The provided input is valid, %s is a valid region", input)
}

t.Cleanup(func() {
GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(0),
}

})

}

func TestValidateRegionWithEnv(t *testing.T) {

GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(2),
}

os.Setenv("AWS_DEFAULT_REGION", "not-valid")
expectedErr := "not-valid is an invalid AWS region. If this is an error please report it"
err := CleanCmd.RunE(CleanCmd, []string{"--profile", "default", "--retain", "2", "--dry-run"})
Expand All @@ -583,45 +609,51 @@ func TestValidateRegionWithEnv(t *testing.T) {
t.Fatalf("Expected an error to be returned but received %v", err.Error())
}

t.Cleanup(func() {
GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(false),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(0),
}

})

}

func TestAWSValidateRegionWithFlag(t *testing.T) {

GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(2),
}

expectedErr := "missing region flag and AWS_DEFAULT_REGION env variable. Please use -r and provide a valid AWS region"
err := CleanCmd.RunE(CleanCmd, []string{"--profile", "default", "--region", "not-valid", "--retain", "2", "--dry-run"})
if err == nil || err.Error() != expectedErr {
t.Fatalf("Expected an error to be returned but received %v", err.Error())
}

t.Cleanup(func() {
GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(0),
}

})
}

func TestAWSInvalidRegion(t *testing.T) {

GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(2),
}

input := "not-valid"
want := "not-valid is an invalid AWS region. If this is an error please report it"
got, err := validateRegion(rr, input)
Expand All @@ -631,7 +663,18 @@ func TestAWSInvalidRegion(t *testing.T) {
}

t.Cleanup(func() {
// Clear all AWS credentials
GlobalCliConfig = cliConfig{
RegionFlag: aws.String(""),
CredentialsFile: aws.Bool(false),
ProfileFlag: aws.String(""),
DryRun: aws.Bool(true),
Verbose: aws.Bool(true),
LambdaListFile: aws.String(""),
MoreLambdaDetails: aws.Bool(true),
SizeIEC: aws.Bool(false),
SkipAliases: aws.Bool(false),
Retain: aws.Int8(0),
}

})
}
Expand Down

0 comments on commit aa0d825

Please sign in to comment.