@@ -18,95 +18,80 @@ func TestAccDataSourceSumoLogicApps_basic(t *testing.T) {
1818 Config : testAccDataSourceSumoLogicAppsConfig_basic ,
1919 Check : resource .ComposeTestCheckFunc (
2020 testAccCheckSumoLogicAppsDataSourceID ("data.sumologic_apps.test" ),
21- //testAccCheckSumoLogicAppsGreaterThanZero("data.sumologic_apps.test"),
22- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "id" ),
23- //resource.TestCheckResourceAttrSet("data.sumologic_apps.test", "apps"),
24- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.0.uuid" ),
25- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.0.name" ),
26- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.0.description" ),
27- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.0.latestVersion" ),
28- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.0.icon" ),
29- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.0.author" ),
30- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.0.appType" ),
31- //resource.TestCheckResourceAttrSet("data.sumologic_apps.test", "apps.0.attributes"),
32- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.0.installable" ),
33- resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.0.showOnMarketplace" ),
21+ resource .TestCheckResourceAttrSet ("data.sumologic_apps.test" , "apps.#" ),
22+ checkResourceAttrGreaterThanZero ("data.sumologic_apps.test" , "apps.#" ),
3423 ),
3524 },
3625 },
3726 })
3827}
3928
40- // func TestAccDataSourceSumoLogicApps_filtered(t *testing.T) {
41- // resource.Test(t, resource.TestCase{
42- // PreCheck: func() { testAccPreCheck(t) },
43- // ProviderFactories: providerFactories ,
44- // Steps: []resource.TestStep{
45- // {
46- // Config: testAccDataSourceSumoLogicAppsConfig_filtered,
47- // Check: resource.ComposeTestCheckFunc(
48- // testAccCheckSumoLogicAppsDataSourceID("data.sumologic_apps.filtered"),
49- // resource.TestCheckResourceAttr("data.sumologic_apps.filtered", "apps.#", "1"),
50- // resource.TestCheckResourceAttr("data.sumologic_apps.filtered", "apps.0.name", "AWS CloudTrail "),
51- // resource.TestCheckResourceAttr("data.sumologic_apps.filtered", "apps.0.author", "Sumo Logic"),
52- // ),
53- // },
54- // },
55- // })
56- // }
29+ func TestAccDataSourceSumoLogicApps_filtered (t * testing.T ) {
30+ resource .Test (t , resource.TestCase {
31+ PreCheck : func () { testAccPreCheck (t ) },
32+ Providers : testAccProviders ,
33+ Steps : []resource.TestStep {
34+ {
35+ Config : testAccDataSourceSumoLogicAppsConfig_filtered ,
36+ Check : resource .ComposeTestCheckFunc (
37+ testAccCheckSumoLogicAppsDataSourceID ("data.sumologic_apps.filtered" ),
38+ resource .TestCheckResourceAttr ("data.sumologic_apps.filtered" , "apps.#" , "1" ),
39+ resource .TestCheckResourceAttr ("data.sumologic_apps.filtered" , "apps.0.name" , "MySQL - OpenTelemetry " ),
40+ resource .TestCheckResourceAttr ("data.sumologic_apps.filtered" , "apps.0.author" , "Sumo Logic" ),
41+ ),
42+ },
43+ },
44+ })
45+ }
5746
58- func testAccCheckSumoLogicAppsGreaterThanZero (n string ) resource.TestCheckFunc {
47+ func testAccCheckSumoLogicAppsDataSourceID (n string ) resource.TestCheckFunc {
5948 return func (s * terraform.State ) error {
6049 rs , ok := s .RootModule ().Resources [n ]
6150 if ! ok {
6251 return fmt .Errorf ("Can't find SumoLogic Apps data source: %s" , n )
6352 }
6453
65- appsCount , ok := rs .Primary .Attributes ["apps.#" ]
66- if ! ok {
67- return fmt .Errorf ("Apps count not found in state" )
68- }
69-
70- count , err := strconv .Atoi (appsCount )
71- if err != nil {
72- return fmt .Errorf ("Failed to parse apps count: %v" , err )
73- }
74-
75- if count <= 0 {
76- return fmt .Errorf ("No apps returned, expected at least one" )
54+ if rs .Primary .ID == "" {
55+ return fmt .Errorf ("SumoLogic Apps data source ID not set" )
7756 }
78-
7957 return nil
8058 }
8159}
8260
83- func testAccCheckSumoLogicAppsDataSourceID ( n string ) resource.TestCheckFunc {
61+ func checkResourceAttrGreaterThanZero ( resourceName , attributeName string ) resource.TestCheckFunc {
8462 return func (s * terraform.State ) error {
63+ rs , ok := s .RootModule ().Resources [resourceName ]
64+ if ! ok {
65+ return fmt .Errorf ("Not found: %s" , resourceName )
66+ }
8567
86- rs , ok := s . RootModule (). Resources [ n ]
68+ attrValue , ok := rs . Primary . Attributes [ attributeName ]
8769 if ! ok {
88- return fmt .Errorf ("Can't find SumoLogic Apps data source : %s" , n )
70+ return fmt .Errorf ("Attribute not found : %s" , attributeName )
8971 }
9072
91- fmt . Printf ( "%v \n " , s . RootModule (). Resources )
92- fmt . Printf ( "%v \n " , rs . Primary )
93- if rs . Primary . ID == "" {
94- return fmt .Errorf ("SumoLogic Apps data source ID not set" )
73+ // Convert the attribute value to an integer
74+ count , err := strconv . Atoi ( attrValue )
75+ if err != nil {
76+ return fmt .Errorf ("Error converting attribute value to integer: %s" , err )
9577 }
78+
79+ // Check if count is greater than 0
80+ if count <= 0 {
81+ return fmt .Errorf ("Expected %s to be greater than 0, got %d" , attributeName , count )
82+ }
83+
9684 return nil
9785 }
9886}
9987
10088const testAccDataSourceSumoLogicAppsConfig_basic = `
101- data "sumologic_apps" "test" {
102- name = "MySQL - OpenTelemetry"
103- author = "Sumo Logic"
104- }
89+ data "sumologic_apps" "test" {}
10590`
10691
10792const testAccDataSourceSumoLogicAppsConfig_filtered = `
10893 data "sumologic_apps" "filtered" {
109- name = "AWS CloudTrail "
94+ name = "MySQL - OpenTelemetry "
11095 author = "Sumo Logic"
11196 }
11297`
0 commit comments