-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ec2): changed to new config but with less checks
- Loading branch information
1 parent
7578eae
commit 652612d
Showing
34 changed files
with
367 additions
and
1,808 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ec2 | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/service/ec2/types" | ||
) | ||
|
||
func Ec2MonitoringEnabledCondition(resource interface{}) bool { | ||
instance, ok := resource.(*types.Instance) | ||
if !ok { | ||
return false | ||
} | ||
return instance.Monitoring.State == types.MonitoringStateEnabled | ||
} | ||
|
||
func Ec2PublicIPCondition(resource interface{}) bool { | ||
instance, ok := resource.(*types.Instance) | ||
if !ok { | ||
return false | ||
} | ||
return instance.PublicIpAddress == nil | ||
} | ||
|
||
func Ec2RunningInVPCCondition(resource interface{}) bool { | ||
instance, ok := resource.(*types.Instance) | ||
if !ok { | ||
return false | ||
} | ||
return instance.VpcId != nil && *instance.VpcId != "" | ||
} | ||
|
||
// Generate unit test functions for each condition |
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,95 @@ | ||
package ec2 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/ec2/types" | ||
) | ||
|
||
// Generate unit tests for EC2 | ||
|
||
func TestEc2MonitoringEnabledCondition(t *testing.T) { | ||
type args struct { | ||
resource interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "TestEc2MonitoringEnabledCondition", | ||
args: args{ | ||
resource: &types.Instance{ | ||
Monitoring: &types.Monitoring{ | ||
State: types.MonitoringStateEnabled, | ||
}, | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := Ec2MonitoringEnabledCondition(tt.args.resource); got != tt.want { | ||
t.Errorf("Ec2MonitoringEnabledCondition() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestEc2PublicIPCondition(t *testing.T) { | ||
type args struct { | ||
resource interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "TestEc2PublicIPCondition", | ||
args: args{ | ||
resource: &types.Instance{ | ||
PublicIpAddress: nil, | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := Ec2PublicIPCondition(tt.args.resource); got != tt.want { | ||
t.Errorf("Ec2PublicIPCondition() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestEc2RunningInVPCCondition(t *testing.T) { | ||
type args struct { | ||
resource interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "TestEc2RunningInVPCCondition", | ||
args: args{ | ||
resource: &types.Instance{ | ||
VpcId: nil, | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := Ec2RunningInVPCCondition(tt.args.resource); got != tt.want { | ||
t.Errorf("Ec2RunningInVPCCondition() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.