4
4
import static org .mockito .Mockito .mock ;
5
5
import static org .mockito .Mockito .when ;
6
6
7
- import com .google .common .collect .Lists ;
8
7
import com .amazonaws .services .autoscaling .model .AutoScalingGroup ;
8
+ import com .amazonaws .services .autoscaling .model .SuspendedProcess ;
9
9
import com .amazonaws .services .autoscaling .model .TagDescription ;
10
+
11
+ import com .google .common .collect .Maps ;
12
+
13
+ import com .netflix .simianarmy .aws .conformity .crawler .AWSClusterCrawler ;
14
+ import com .netflix .simianarmy .basic .BasicConfiguration ;
15
+ import com .netflix .simianarmy .basic .conformity .BasicConformityMonkeyContext ;
10
16
import com .netflix .simianarmy .conformity .Cluster ;
11
17
import com .netflix .simianarmy .client .aws .AWSClient ;
12
18
13
19
import junit .framework .Assert ;
14
20
import org .testng .annotations .Test ;
15
21
22
+ import java .util .Map ;
16
23
import java .util .List ;
17
24
import java .util .LinkedList ;
25
+ import java .util .Properties ;
18
26
19
27
public class TestASGOwnerEmailTag {
28
+
20
29
private static final String ASG1 = "asg1" ;
21
30
private static final String ASG2 = "asg2" ;
22
- private static final String INSTANCE_ID = "i-01234567890" ;
23
31
private static final String OWNER_TAG_KEY = "owner" ;
24
32
private static final String OWNER_TAG_VALUE = "tyler@paperstreet.com" ;
25
33
private static final String REGION = "eu-west-1" ;
26
34
27
35
@ Test
28
36
public void testForOwnerTag () {
37
+ Properties properties = new Properties ();
38
+ BasicConformityMonkeyContext ctx = new BasicConformityMonkeyContext ();
39
+
29
40
List <AutoScalingGroup > asgList = createASGList ();
30
41
String [] asgNames = {ASG1 , ASG2 };
42
+
31
43
AWSClient awsMock = createMockAWSClient (asgList , asgNames );
32
- List <Cluster > list = Lists .newArrayList ();
33
-
34
- for (AutoScalingGroup asg : asgList ) {
35
- List <String > instances = Lists .newArrayList ();
36
- instances .add (INSTANCE_ID );
37
- com .netflix .simianarmy .conformity .AutoScalingGroup conformityAsg =
38
- new com .netflix .simianarmy .conformity .AutoScalingGroup (
39
- asg .getAutoScalingGroupName (),
40
- instances .toArray (new String [instances .size ()]));
41
- Cluster cluster = new Cluster (asg .getAutoScalingGroupName (), REGION , conformityAsg );
42
- List <TagDescription > tagDescriptions = asg .getTags ();
43
- for (TagDescription tagDescription : tagDescriptions ) {
44
- if ( tagDescription .getKey () != null ) {
45
- if ( OWNER_TAG_KEY .equalsIgnoreCase (tagDescription .getKey ()) ) {
46
- String value = tagDescription .getValue ();
47
- if (value != null ) {
48
- cluster .setOwnerEmail (value );
49
- }
50
- }
51
- }
52
- }
53
- list .add (cluster );
54
- }
44
+ Map <String , AWSClient > regionToAwsClient = Maps .newHashMap ();
45
+ regionToAwsClient .put ("us-east-1" , awsMock );
46
+ AWSClusterCrawler clusterCrawler = new AWSClusterCrawler (regionToAwsClient , new BasicConfiguration (properties ));
47
+
48
+ List <Cluster > clusters = clusterCrawler .clusters (asgNames );
55
49
56
- Assert .assertNotNull (list .get (0 ).getOwnerEmail ());
57
- Assert .assertTrue (list .get (0 ).getOwnerEmail ().equalsIgnoreCase (OWNER_TAG_VALUE ));
58
- Assert .assertEquals (list .get (1 ).getOwnerEmail (), null );
50
+ Assert .assertTrue (OWNER_TAG_VALUE .equalsIgnoreCase (clusters .get (0 ).getOwnerEmail ()));
51
+ Assert .assertNull (clusters .get (1 ).getOwnerEmail ());
59
52
}
60
53
61
54
private List <AutoScalingGroup > createASGList () {
@@ -64,17 +57,18 @@ private List<AutoScalingGroup> createASGList() {
64
57
asgList .add (makeASG (ASG2 , null ));
65
58
return asgList ;
66
59
}
60
+
61
+ private AutoScalingGroup makeASG (String asgName , String ownerEmail ) {
62
+ TagDescription tag = new TagDescription ().withKey (OWNER_TAG_KEY ).withValue (ownerEmail );
63
+ AutoScalingGroup asg = new AutoScalingGroup ()
64
+ .withAutoScalingGroupName (asgName )
65
+ .withTags (tag );
66
+ return asg ;
67
+ }
67
68
68
69
private AWSClient createMockAWSClient (List <AutoScalingGroup > asgList , String ... asgNames ) {
69
70
AWSClient awsMock = mock (AWSClient .class );
70
71
when (awsMock .describeAutoScalingGroups (asgNames )).thenReturn (asgList );
71
72
return awsMock ;
72
73
}
73
-
74
- private AutoScalingGroup makeASG (String asgName , String ownerEmail ) {
75
- TagDescription tag = new TagDescription ().withKey (OWNER_TAG_KEY ).withValue (ownerEmail );
76
- AutoScalingGroup asg = new AutoScalingGroup ().withAutoScalingGroupName (asgName ).withTags (tag );
77
- return asg ;
78
- }
79
-
80
74
}
0 commit comments