@@ -20,6 +20,7 @@ import (
20
20
"github.com/aws/amazon-cloudwatch-agent/cfg/envconfig"
21
21
"github.com/aws/amazon-cloudwatch-agent/internal/merge/confmap"
22
22
"github.com/aws/amazon-cloudwatch-agent/logger"
23
+ "github.com/aws/amazon-cloudwatch-agent/tool/paths"
23
24
)
24
25
25
26
func Test_getCollectorParams (t * testing.T ) {
@@ -154,6 +155,52 @@ service:
154
155
}
155
156
}
156
157
158
+ func TestFallbackOtelConfig (t * testing.T ) {
159
+ defaultYamlRelativePath := filepath .Join ("default" , paths .YAML )
160
+ testCases := map [string ]struct {
161
+ tomlRelativePath string
162
+ filesToCreate []string
163
+ want string
164
+ }{
165
+ "WithoutAnyFiles" : {
166
+ tomlRelativePath : filepath .Join ("config" , "config.toml" ),
167
+ want : defaultYamlRelativePath ,
168
+ },
169
+ "WithDefaultYamlPath" : {
170
+ tomlRelativePath : filepath .Join ("config" , "config.toml" ),
171
+ filesToCreate : []string {defaultYamlRelativePath , filepath .Join ("config" , paths .YAML )},
172
+ want : defaultYamlRelativePath ,
173
+ },
174
+ "WithDefaultYamlInTomlDir" : {
175
+ tomlRelativePath : filepath .Join ("config" , "config.toml" ),
176
+ filesToCreate : []string {filepath .Join ("config" , paths .YAML ), filepath .Join ("config" , "config.yaml" )},
177
+ want : filepath .Join ("config" , paths .YAML ),
178
+ },
179
+ "WithSameNameAsToml" : {
180
+ tomlRelativePath : filepath .Join ("config" , "config.toml" ),
181
+ filesToCreate : []string {filepath .Join ("config" , "config.yaml" )},
182
+ want : filepath .Join ("config" , "config.yaml" ),
183
+ },
184
+ "WithoutTomlPath" : {
185
+ tomlRelativePath : "" ,
186
+ filesToCreate : []string {filepath .Join ("config" , "config.yaml" )},
187
+ want : defaultYamlRelativePath ,
188
+ },
189
+ }
190
+ for name , testCase := range testCases {
191
+ t .Run (name , func (t * testing.T ) {
192
+ tmpDir := t .TempDir ()
193
+ for _ , fileToCreate := range testCase .filesToCreate {
194
+ path := filepath .Join (tmpDir , fileToCreate )
195
+ require .NoError (t , os .MkdirAll (filepath .Dir (path ), 0755 ))
196
+ require .NoError (t , os .WriteFile (path , nil , 0600 ))
197
+ }
198
+ got := getFallbackOtelConfig (filepath .Join (tmpDir , testCase .tomlRelativePath ), filepath .Join (tmpDir , defaultYamlRelativePath ))
199
+ assert .Equal (t , filepath .Join (tmpDir , testCase .want ), got )
200
+ })
201
+ }
202
+ }
203
+
157
204
func mustLoadFromFile (t * testing.T , path string ) * confmap.Conf {
158
205
conf , err := confmap .NewFileLoader (path ).Load ()
159
206
require .NoError (t , err )
0 commit comments