1
+ // CHECKSTYLE IGNORE Javadoc
2
+ package com .netflix .simianarmy .aws .conformity ;
3
+
4
+ import static org .mockito .Mockito .mock ;
5
+ import static org .mockito .Mockito .when ;
6
+
7
+ import com .amazonaws .services .autoscaling .model .AutoScalingGroup ;
8
+ import com .amazonaws .services .autoscaling .model .SuspendedProcess ;
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 ;
16
+ import com .netflix .simianarmy .conformity .Cluster ;
17
+ import com .netflix .simianarmy .client .aws .AWSClient ;
18
+
19
+ import junit .framework .Assert ;
20
+ import org .testng .annotations .Test ;
21
+
22
+ import java .util .Map ;
23
+ import java .util .List ;
24
+ import java .util .LinkedList ;
25
+ import java .util .Properties ;
26
+
27
+ public class TestASGOwnerEmailTag {
28
+
29
+ private static final String ASG1 = "asg1" ;
30
+ private static final String ASG2 = "asg2" ;
31
+ private static final String OWNER_TAG_KEY = "owner" ;
32
+ private static final String OWNER_TAG_VALUE = "tyler@paperstreet.com" ;
33
+ private static final String REGION = "eu-west-1" ;
34
+
35
+ @ Test
36
+ public void testForOwnerTag () {
37
+ Properties properties = new Properties ();
38
+ BasicConformityMonkeyContext ctx = new BasicConformityMonkeyContext ();
39
+
40
+ List <AutoScalingGroup > asgList = createASGList ();
41
+ String [] asgNames = {ASG1 , ASG2 };
42
+
43
+ AWSClient awsMock = createMockAWSClient (asgList , asgNames );
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 );
49
+
50
+ Assert .assertTrue (OWNER_TAG_VALUE .equalsIgnoreCase (clusters .get (0 ).getOwnerEmail ()));
51
+ Assert .assertNull (clusters .get (1 ).getOwnerEmail ());
52
+ }
53
+
54
+ private List <AutoScalingGroup > createASGList () {
55
+ List <AutoScalingGroup > asgList = new LinkedList <AutoScalingGroup >();
56
+ asgList .add (makeASG (ASG1 , OWNER_TAG_VALUE ));
57
+ asgList .add (makeASG (ASG2 , null ));
58
+ return asgList ;
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
+ }
68
+
69
+ private AWSClient createMockAWSClient (List <AutoScalingGroup > asgList , String ... asgNames ) {
70
+ AWSClient awsMock = mock (AWSClient .class );
71
+ when (awsMock .describeAutoScalingGroups (asgNames )).thenReturn (asgList );
72
+ return awsMock ;
73
+ }
74
+ }
0 commit comments