@@ -69,3 +69,110 @@ func TestWithDefaultValues(t *testing.T) {
6969 // Assert if the logs are sent to Sumo Logic.
7070 assertResource .CheckLogsForPastSixtyMinutes ("_sourceid=" + outputs ["sumologic_source" ].(map [string ]interface {})["id" ].(string ), 5 , 2 * time .Minute )
7171}
72+
73+ func TestWithExistingValues (t * testing.T ) {
74+ t .Parallel ()
75+ aws_region := "us-east-2"
76+ vars := map [string ]interface {}{
77+ "create_collector" : false ,
78+ "source_details" : map [string ]interface {}{
79+ "source_name" : "Cloudwatch source" ,
80+ "source_category" : "Labs/cloudwatch/logs" ,
81+ "description" : "This is an description." ,
82+ "collector_id" : COLLECTOR_ID ,
83+ "fields" : map [string ]interface {}{
84+ "account" : "MyValue" ,
85+ },
86+ },
87+ "auto_enable_logs_subscription" : "Existing" ,
88+ }
89+
90+ options , count := SetUpTest (t , vars , aws_region )
91+
92+ // Assert count of Expected resources.
93+ test_structure .RunTestStage (t , "AssertCount" , func () {
94+ common .AssertResourceCounts (t , count , 22 , 0 , 0 )
95+ })
96+
97+ assertResource := common .GetAssertResource (t , options .EnvVars )
98+ outputs := common .FetchAllOutputs (t , options )
99+ replacementMap := map [string ]interface {}{
100+ "AccountId" : aws .GetAccountId (t ),
101+ "Region" : aws_region ,
102+ "SumoAccountId" : common .SumoAccountId ,
103+ "Deployment" : common .SumologicEnvironment ,
104+ "OrgId" : common .SumologicOrganizationId ,
105+ "RandomString" : outputs ["random_string" ].(map [string ]interface {})["id" ].(string ),
106+ "URL" : outputs ["sumologic_source" ].(map [string ]interface {})["url" ].(string ),
107+ }
108+ // Assert if the outputs are actually created in AWS and Sumo Logic.
109+ // This also checks if your expectation are matched with the outputs, so provide an JSON with expected outputs.
110+ expectedOutputs := common .ReadJsonFile ("TestWithExistingValues.json" , replacementMap )
111+ test_structure .RunTestStage (t , "AssertOutputs" , func () {
112+ common .AssertOutputsWithLookup (t , options , expectedOutputs , LOOK_UP_MAP )
113+ })
114+
115+ // Assert if the logs are sent to Sumo Logic.
116+ assertResource .CheckLogsForPastSixtyMinutes ("_sourceid=" + outputs ["sumologic_source" ].(map [string ]interface {})["id" ].(string ), 5 , 2 * time .Minute )
117+ }
118+
119+ func TestUpdates (t * testing.T ) {
120+ t .Parallel ()
121+ aws_region := "us-west-2"
122+ vars := map [string ]interface {}{
123+ "create_collector" : true ,
124+ "collector_details" : map [string ]interface {}{
125+ "collector_name" : "Test Updates" ,
126+ "description" : "This collector is created for testing elb terraform module." ,
127+ "fields" : map [string ]interface {}{
128+ "MyCollector" : "TestTerraform" ,
129+ },
130+ },
131+ "auto_enable_logs_subscription" : "Existing" ,
132+ }
133+
134+ options , count := SetUpTest (t , vars , aws_region )
135+
136+ // Assert count of Expected resources.
137+ test_structure .RunTestStage (t , "AssertCount" , func () {
138+ common .AssertResourceCounts (t , count , 23 , 0 , 0 )
139+ })
140+
141+ vars = map [string ]interface {}{
142+ "create_collector" : true ,
143+ "collector_details" : map [string ]interface {}{
144+ "collector_name" : "Test Updates Again" ,
145+ "description" : "This collector is created for testing elb terraform module." ,
146+ "fields" : map [string ]interface {}{
147+ "MyCollector" : "TestTerraform" ,
148+ },
149+ },
150+ "auto_enable_logs_subscription" : "None" ,
151+ }
152+
153+ count = UpdateTerraform (t , vars , options )
154+
155+ test_structure .RunTestStage (t , "UpdateFirst" , func () {
156+ common .AssertResourceCounts (t , count , 0 , 1 , 1 )
157+ })
158+
159+ vars = map [string ]interface {}{
160+ "create_collector" : false ,
161+ "auto_enable_logs_subscription" : "None" ,
162+ "source_details" : map [string ]interface {}{
163+ "source_name" : "Test Source For Logs Two" ,
164+ "source_category" : "My/Test/cvategory" ,
165+ "collector_id" : COLLECTOR_ID ,
166+ "description" : "This is jsyd" ,
167+ "fields" : map [string ]string {
168+ "TestCollector" : "MyValue" ,
169+ },
170+ },
171+ }
172+
173+ count = UpdateTerraform (t , vars , options )
174+
175+ test_structure .RunTestStage (t , "UpdateFirst" , func () {
176+ common .AssertResourceCounts (t , count , 1 , 2 , 2 )
177+ })
178+ }
0 commit comments