2
0

controller_test.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. package config
  2. import (
  3. "testing"
  4. cloudconfig "github.com/opencost/opencost/pkg/cloud"
  5. "github.com/opencost/opencost/pkg/cloud/aws"
  6. "github.com/opencost/opencost/pkg/cloud/gcp"
  7. )
  8. // Baseline valid config
  9. var validAthenaConf = &aws.AthenaConfiguration{
  10. Bucket: "bucket",
  11. Region: "region",
  12. Database: "database",
  13. Table: "table",
  14. Workgroup: "workgroup",
  15. Account: "account",
  16. Authorizer: &aws.ServiceAccount{},
  17. }
  18. // Config with the same key as the baseline but is not equal to it because of the change in the non-keyed property Workgroup
  19. var validAthenaConfModifiedProperty = &aws.AthenaConfiguration{
  20. Bucket: "bucket",
  21. Region: "region",
  22. Database: "database",
  23. Table: "table",
  24. Workgroup: "workgroup1",
  25. Account: "account",
  26. Authorizer: &aws.ServiceAccount{},
  27. }
  28. // Config with the same key as baseline but is invalid due to missing Authorizer
  29. var invalidAthenaConf = &aws.AthenaConfiguration{
  30. Bucket: "bucket",
  31. Region: "region",
  32. Database: "database",
  33. Table: "table",
  34. Workgroup: "workgroup",
  35. Account: "account",
  36. Authorizer: nil,
  37. }
  38. // A valid config with a different key from the baseline
  39. var validBigQueryConf = &gcp.BigQueryConfiguration{
  40. ProjectID: "projectID",
  41. Dataset: "dataset",
  42. Table: "table",
  43. Authorizer: &gcp.WorkloadIdentity{},
  44. }
  45. func TestIntegrationController_pullWatchers(t *testing.T) {
  46. testCases := map[string]struct {
  47. initialStatuses []*Status
  48. configWatchers map[ConfigSource]cloudconfig.KeyedConfigWatcher
  49. expectedStatuses []*Status
  50. }{
  51. // Helm Source
  52. "Helm Source init": {
  53. initialStatuses: []*Status{},
  54. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  55. HelmSource: &MockKeyedConfigWatcher{
  56. Integrations: []cloudconfig.KeyedConfig{
  57. validAthenaConf,
  58. },
  59. },
  60. },
  61. expectedStatuses: []*Status{
  62. {
  63. Source: HelmSource,
  64. Key: validAthenaConf.Key(),
  65. Active: true,
  66. Valid: true,
  67. Config: validAthenaConf,
  68. },
  69. },
  70. },
  71. "Helm Source No Change": {
  72. initialStatuses: []*Status{
  73. {
  74. Source: HelmSource,
  75. Key: validAthenaConf.Key(),
  76. Active: true,
  77. Valid: true,
  78. Config: validAthenaConf,
  79. },
  80. },
  81. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  82. HelmSource: &MockKeyedConfigWatcher{
  83. Integrations: []cloudconfig.KeyedConfig{
  84. validAthenaConf,
  85. },
  86. },
  87. },
  88. expectedStatuses: []*Status{
  89. {
  90. Source: HelmSource,
  91. Key: validAthenaConf.Key(),
  92. Active: true,
  93. Valid: true,
  94. Config: validAthenaConf,
  95. },
  96. },
  97. },
  98. "Helm Source Update Config": {
  99. initialStatuses: []*Status{
  100. {
  101. Source: HelmSource,
  102. Key: validAthenaConfModifiedProperty.Key(),
  103. Active: true,
  104. Valid: true,
  105. Config: validAthenaConfModifiedProperty,
  106. },
  107. },
  108. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  109. HelmSource: &MockKeyedConfigWatcher{
  110. Integrations: []cloudconfig.KeyedConfig{
  111. validAthenaConf,
  112. },
  113. },
  114. },
  115. expectedStatuses: []*Status{
  116. {
  117. Source: HelmSource,
  118. Key: validAthenaConf.Key(),
  119. Active: true,
  120. Valid: true,
  121. Config: validAthenaConf,
  122. },
  123. },
  124. },
  125. "Helm Source Update Config Invalid": {
  126. initialStatuses: []*Status{
  127. {
  128. Source: HelmSource,
  129. Key: validAthenaConf.Key(),
  130. Active: true,
  131. Valid: true,
  132. Config: validAthenaConf,
  133. },
  134. },
  135. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  136. HelmSource: &MockKeyedConfigWatcher{
  137. Integrations: []cloudconfig.KeyedConfig{
  138. invalidAthenaConf,
  139. },
  140. },
  141. },
  142. expectedStatuses: []*Status{
  143. {
  144. Source: HelmSource,
  145. Key: invalidAthenaConf.Key(),
  146. Active: false,
  147. Valid: false,
  148. Config: invalidAthenaConf,
  149. },
  150. },
  151. },
  152. "Helm Source New Config": {
  153. initialStatuses: []*Status{
  154. {
  155. Source: HelmSource,
  156. Key: validAthenaConf.Key(),
  157. Active: true,
  158. Valid: true,
  159. Config: validAthenaConf,
  160. },
  161. },
  162. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  163. HelmSource: &MockKeyedConfigWatcher{
  164. Integrations: []cloudconfig.KeyedConfig{
  165. validBigQueryConf,
  166. },
  167. },
  168. },
  169. expectedStatuses: []*Status{
  170. {
  171. Source: HelmSource,
  172. Key: validAthenaConf.Key(),
  173. Active: false, // this value changed
  174. Valid: true,
  175. Config: validAthenaConf,
  176. },
  177. {
  178. Source: HelmSource,
  179. Key: validBigQueryConf.Key(),
  180. Active: true,
  181. Valid: true,
  182. Config: validBigQueryConf,
  183. },
  184. },
  185. },
  186. // Config File
  187. "Config File Source init": {
  188. initialStatuses: []*Status{},
  189. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  190. ConfigFileSource: &MockKeyedConfigWatcher{
  191. Integrations: []cloudconfig.KeyedConfig{
  192. validAthenaConf,
  193. },
  194. },
  195. },
  196. expectedStatuses: []*Status{
  197. {
  198. Source: ConfigFileSource,
  199. Key: validAthenaConf.Key(),
  200. Active: true,
  201. Valid: true,
  202. Config: validAthenaConf,
  203. },
  204. },
  205. },
  206. "Config File No Change": {
  207. initialStatuses: []*Status{
  208. {
  209. Source: ConfigFileSource,
  210. Key: validAthenaConf.Key(),
  211. Active: true,
  212. Valid: true,
  213. Config: validAthenaConf,
  214. },
  215. },
  216. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  217. ConfigFileSource: &MockKeyedConfigWatcher{
  218. Integrations: []cloudconfig.KeyedConfig{
  219. validAthenaConf,
  220. },
  221. },
  222. },
  223. expectedStatuses: []*Status{
  224. {
  225. Source: ConfigFileSource,
  226. Key: validAthenaConf.Key(),
  227. Active: true,
  228. Valid: true,
  229. Config: validAthenaConf,
  230. },
  231. },
  232. },
  233. "Config File Update Config": {
  234. initialStatuses: []*Status{
  235. {
  236. Source: ConfigFileSource,
  237. Key: validAthenaConf.Key(),
  238. Active: true,
  239. Valid: true,
  240. Config: validAthenaConf,
  241. },
  242. },
  243. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  244. ConfigFileSource: &MockKeyedConfigWatcher{
  245. Integrations: []cloudconfig.KeyedConfig{
  246. validAthenaConf,
  247. },
  248. },
  249. },
  250. expectedStatuses: []*Status{
  251. {
  252. Source: ConfigFileSource,
  253. Key: validAthenaConf.Key(),
  254. Active: true,
  255. Valid: true,
  256. Config: validAthenaConf,
  257. },
  258. },
  259. },
  260. "Config File Update Config Invalid": {
  261. initialStatuses: []*Status{
  262. {
  263. Source: ConfigFileSource,
  264. Key: validAthenaConf.Key(),
  265. Active: true,
  266. Valid: true,
  267. Config: validAthenaConf,
  268. },
  269. },
  270. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  271. ConfigFileSource: &MockKeyedConfigWatcher{
  272. Integrations: []cloudconfig.KeyedConfig{
  273. invalidAthenaConf,
  274. },
  275. },
  276. },
  277. expectedStatuses: []*Status{
  278. {
  279. Source: ConfigFileSource,
  280. Key: invalidAthenaConf.Key(),
  281. Active: false,
  282. Valid: false,
  283. Config: invalidAthenaConf,
  284. },
  285. },
  286. },
  287. "Config File New Config": {
  288. initialStatuses: []*Status{
  289. {
  290. Source: ConfigFileSource,
  291. Key: validAthenaConf.Key(),
  292. Active: true,
  293. Valid: true,
  294. Config: validAthenaConf,
  295. },
  296. },
  297. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  298. ConfigFileSource: &MockKeyedConfigWatcher{
  299. Integrations: []cloudconfig.KeyedConfig{
  300. validBigQueryConf,
  301. },
  302. },
  303. },
  304. expectedStatuses: []*Status{
  305. {
  306. Source: ConfigFileSource,
  307. Key: validAthenaConf.Key(),
  308. Active: false, // this value changed
  309. Valid: true,
  310. Config: validAthenaConf,
  311. },
  312. {
  313. Source: ConfigFileSource,
  314. Key: validBigQueryConf.Key(),
  315. Active: true,
  316. Valid: true,
  317. Config: validBigQueryConf,
  318. },
  319. },
  320. },
  321. // Multi Cloud
  322. "Multi Cloud Source init": {
  323. initialStatuses: []*Status{},
  324. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  325. MultiCloudSource: &MockKeyedConfigWatcher{
  326. Integrations: []cloudconfig.KeyedConfig{
  327. validAthenaConf,
  328. },
  329. },
  330. },
  331. expectedStatuses: []*Status{
  332. {
  333. Source: MultiCloudSource,
  334. Key: validAthenaConf.Key(),
  335. Active: true,
  336. Valid: true,
  337. Config: validAthenaConf,
  338. },
  339. },
  340. },
  341. "Multi Cloud No Change": {
  342. initialStatuses: []*Status{
  343. {
  344. Source: MultiCloudSource,
  345. Key: validAthenaConf.Key(),
  346. Active: true,
  347. Valid: true,
  348. Config: validAthenaConf,
  349. },
  350. },
  351. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  352. MultiCloudSource: &MockKeyedConfigWatcher{
  353. Integrations: []cloudconfig.KeyedConfig{
  354. validAthenaConf,
  355. },
  356. },
  357. },
  358. expectedStatuses: []*Status{
  359. {
  360. Source: MultiCloudSource,
  361. Key: validAthenaConf.Key(),
  362. Active: true,
  363. Valid: true,
  364. Config: validAthenaConf,
  365. },
  366. },
  367. },
  368. "Multi Cloud Update Config": {
  369. initialStatuses: []*Status{
  370. {
  371. Source: MultiCloudSource,
  372. Key: validAthenaConf.Key(),
  373. Active: true,
  374. Valid: true,
  375. Config: validAthenaConf,
  376. },
  377. },
  378. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  379. MultiCloudSource: &MockKeyedConfigWatcher{
  380. Integrations: []cloudconfig.KeyedConfig{
  381. validAthenaConfModifiedProperty,
  382. },
  383. },
  384. },
  385. expectedStatuses: []*Status{
  386. {
  387. Source: MultiCloudSource,
  388. Key: validAthenaConfModifiedProperty.Key(),
  389. Active: true,
  390. Valid: true,
  391. Config: validAthenaConfModifiedProperty,
  392. },
  393. },
  394. },
  395. "Multi Cloud Update Config Invalid": {
  396. initialStatuses: []*Status{
  397. {
  398. Source: MultiCloudSource,
  399. Key: validAthenaConf.Key(),
  400. Active: true,
  401. Valid: true,
  402. Config: validAthenaConf,
  403. },
  404. },
  405. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  406. MultiCloudSource: &MockKeyedConfigWatcher{
  407. Integrations: []cloudconfig.KeyedConfig{
  408. invalidAthenaConf,
  409. },
  410. },
  411. },
  412. expectedStatuses: []*Status{
  413. {
  414. Source: MultiCloudSource,
  415. Key: invalidAthenaConf.Key(),
  416. Active: false,
  417. Valid: false,
  418. Config: invalidAthenaConf,
  419. },
  420. },
  421. },
  422. "Multi Cloud New Config": {
  423. initialStatuses: []*Status{
  424. {
  425. Source: MultiCloudSource,
  426. Key: validAthenaConf.Key(),
  427. Active: true,
  428. Valid: true,
  429. Config: validAthenaConf,
  430. },
  431. },
  432. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  433. MultiCloudSource: &MockKeyedConfigWatcher{
  434. Integrations: []cloudconfig.KeyedConfig{
  435. validBigQueryConf,
  436. },
  437. },
  438. },
  439. expectedStatuses: []*Status{
  440. {
  441. Source: MultiCloudSource,
  442. Key: validAthenaConf.Key(),
  443. Active: true,
  444. Valid: true,
  445. Config: validAthenaConf,
  446. },
  447. {
  448. Source: MultiCloudSource,
  449. Key: validBigQueryConf.Key(),
  450. Active: true,
  451. Valid: true,
  452. Config: validBigQueryConf,
  453. },
  454. },
  455. },
  456. // Watch Interaction
  457. "New Helm, Existing Config File": {
  458. initialStatuses: []*Status{
  459. {
  460. Source: ConfigFileSource,
  461. Key: validAthenaConf.Key(),
  462. Active: true,
  463. Valid: true,
  464. Config: validAthenaConf,
  465. },
  466. },
  467. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  468. ConfigFileSource: &MockKeyedConfigWatcher{
  469. Integrations: []cloudconfig.KeyedConfig{
  470. validAthenaConf,
  471. },
  472. },
  473. HelmSource: &MockKeyedConfigWatcher{
  474. Integrations: []cloudconfig.KeyedConfig{
  475. validBigQueryConf,
  476. },
  477. },
  478. },
  479. expectedStatuses: []*Status{
  480. {
  481. Source: ConfigFileSource,
  482. Key: validAthenaConf.Key(),
  483. Active: false,
  484. Valid: true,
  485. Config: validAthenaConf,
  486. },
  487. {
  488. Source: HelmSource,
  489. Key: validBigQueryConf.Key(),
  490. Active: true,
  491. Valid: true,
  492. Config: validBigQueryConf,
  493. },
  494. },
  495. },
  496. "Update Helm, Existing Config File": {
  497. initialStatuses: []*Status{
  498. {
  499. Source: HelmSource,
  500. Key: validAthenaConf.Key(),
  501. Active: false,
  502. Valid: true,
  503. Config: validAthenaConf,
  504. },
  505. {
  506. Source: ConfigFileSource,
  507. Key: validBigQueryConf.Key(),
  508. Active: true,
  509. Valid: true,
  510. Config: validBigQueryConf,
  511. },
  512. },
  513. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  514. ConfigFileSource: &MockKeyedConfigWatcher{
  515. Integrations: []cloudconfig.KeyedConfig{
  516. validBigQueryConf,
  517. },
  518. },
  519. HelmSource: &MockKeyedConfigWatcher{
  520. Integrations: []cloudconfig.KeyedConfig{
  521. validAthenaConfModifiedProperty,
  522. },
  523. },
  524. },
  525. expectedStatuses: []*Status{
  526. {
  527. Source: HelmSource,
  528. Key: validAthenaConfModifiedProperty.Key(),
  529. Active: true,
  530. Valid: true,
  531. Config: validAthenaConfModifiedProperty,
  532. },
  533. {
  534. Source: ConfigFileSource,
  535. Key: validBigQueryConf.Key(),
  536. Active: false,
  537. Valid: true,
  538. Config: validBigQueryConf,
  539. },
  540. },
  541. },
  542. "New Helm Invalid, Existing Config File": {
  543. initialStatuses: []*Status{
  544. {
  545. Source: ConfigFileSource,
  546. Key: validBigQueryConf.Key(),
  547. Active: true,
  548. Valid: true,
  549. Config: validBigQueryConf,
  550. },
  551. },
  552. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  553. ConfigFileSource: &MockKeyedConfigWatcher{
  554. Integrations: []cloudconfig.KeyedConfig{
  555. validBigQueryConf,
  556. },
  557. },
  558. HelmSource: &MockKeyedConfigWatcher{
  559. Integrations: []cloudconfig.KeyedConfig{
  560. invalidAthenaConf,
  561. },
  562. },
  563. },
  564. expectedStatuses: []*Status{
  565. {
  566. Source: ConfigFileSource,
  567. Key: validBigQueryConf.Key(),
  568. Active: true,
  569. Valid: true,
  570. Config: validBigQueryConf,
  571. },
  572. {
  573. Source: HelmSource,
  574. Key: invalidAthenaConf.Key(),
  575. Active: false,
  576. Valid: false,
  577. Config: invalidAthenaConf,
  578. },
  579. },
  580. },
  581. "Update Helm Invalid, Existing Config File": {
  582. initialStatuses: []*Status{
  583. {
  584. Source: ConfigFileSource,
  585. Key: validBigQueryConf.Key(),
  586. Active: true,
  587. Valid: true,
  588. Config: validBigQueryConf,
  589. },
  590. {
  591. Source: HelmSource,
  592. Key: validAthenaConf.Key(),
  593. Active: false,
  594. Valid: true,
  595. Config: validAthenaConf,
  596. },
  597. },
  598. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  599. ConfigFileSource: &MockKeyedConfigWatcher{
  600. Integrations: []cloudconfig.KeyedConfig{
  601. validBigQueryConf,
  602. },
  603. },
  604. HelmSource: &MockKeyedConfigWatcher{
  605. Integrations: []cloudconfig.KeyedConfig{
  606. invalidAthenaConf,
  607. },
  608. },
  609. },
  610. expectedStatuses: []*Status{
  611. {
  612. Source: ConfigFileSource,
  613. Key: validBigQueryConf.Key(),
  614. Active: true,
  615. Valid: true,
  616. Config: validBigQueryConf,
  617. },
  618. {
  619. Source: HelmSource,
  620. Key: invalidAthenaConf.Key(),
  621. Active: false,
  622. Valid: false,
  623. Config: invalidAthenaConf,
  624. },
  625. },
  626. },
  627. "New Config File, Existing Helm": {
  628. initialStatuses: []*Status{
  629. {
  630. Source: HelmSource,
  631. Key: validAthenaConf.Key(),
  632. Active: true,
  633. Valid: true,
  634. Config: validAthenaConf,
  635. },
  636. },
  637. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  638. HelmSource: &MockKeyedConfigWatcher{
  639. Integrations: []cloudconfig.KeyedConfig{
  640. validAthenaConf,
  641. },
  642. },
  643. ConfigFileSource: &MockKeyedConfigWatcher{
  644. Integrations: []cloudconfig.KeyedConfig{
  645. validBigQueryConf,
  646. },
  647. },
  648. },
  649. expectedStatuses: []*Status{
  650. {
  651. Source: HelmSource,
  652. Key: validAthenaConf.Key(),
  653. Active: false,
  654. Valid: true,
  655. Config: validAthenaConf,
  656. },
  657. {
  658. Source: ConfigFileSource,
  659. Key: validBigQueryConf.Key(),
  660. Active: true,
  661. Valid: true,
  662. Config: validBigQueryConf,
  663. },
  664. },
  665. },
  666. "Update Config File, Existing Helm": {
  667. initialStatuses: []*Status{
  668. {
  669. Source: ConfigFileSource,
  670. Key: validAthenaConf.Key(),
  671. Active: false,
  672. Valid: true,
  673. Config: validAthenaConf,
  674. },
  675. {
  676. Source: HelmSource,
  677. Key: validBigQueryConf.Key(),
  678. Active: true,
  679. Valid: true,
  680. Config: validBigQueryConf,
  681. },
  682. },
  683. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  684. HelmSource: &MockKeyedConfigWatcher{
  685. Integrations: []cloudconfig.KeyedConfig{},
  686. },
  687. ConfigFileSource: &MockKeyedConfigWatcher{
  688. Integrations: []cloudconfig.KeyedConfig{
  689. validAthenaConfModifiedProperty,
  690. },
  691. },
  692. },
  693. expectedStatuses: []*Status{
  694. {
  695. Source: ConfigFileSource,
  696. Key: validAthenaConfModifiedProperty.Key(),
  697. Active: true,
  698. Valid: true,
  699. Config: validAthenaConfModifiedProperty,
  700. },
  701. {
  702. Source: HelmSource,
  703. Key: validBigQueryConf.Key(),
  704. Active: false,
  705. Valid: true,
  706. Config: validBigQueryConf,
  707. },
  708. },
  709. },
  710. "New Config File Invalid, Existing Helm": {
  711. initialStatuses: []*Status{
  712. {
  713. Source: HelmSource,
  714. Key: validBigQueryConf.Key(),
  715. Active: true,
  716. Valid: true,
  717. Config: validBigQueryConf,
  718. },
  719. },
  720. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  721. HelmSource: &MockKeyedConfigWatcher{
  722. Integrations: []cloudconfig.KeyedConfig{
  723. validBigQueryConf,
  724. },
  725. },
  726. ConfigFileSource: &MockKeyedConfigWatcher{
  727. Integrations: []cloudconfig.KeyedConfig{
  728. invalidAthenaConf,
  729. },
  730. },
  731. },
  732. expectedStatuses: []*Status{
  733. {
  734. Source: HelmSource,
  735. Key: validBigQueryConf.Key(),
  736. Active: true,
  737. Valid: true,
  738. Config: validBigQueryConf,
  739. },
  740. {
  741. Source: ConfigFileSource,
  742. Key: invalidAthenaConf.Key(),
  743. Active: false,
  744. Valid: false,
  745. Config: invalidAthenaConf,
  746. },
  747. },
  748. },
  749. "Update Config File Invalid, Existing Helm": {
  750. initialStatuses: []*Status{
  751. {
  752. Source: HelmSource,
  753. Key: validBigQueryConf.Key(),
  754. Active: true,
  755. Valid: true,
  756. Config: validBigQueryConf,
  757. },
  758. {
  759. Source: ConfigFileSource,
  760. Key: validAthenaConf.Key(),
  761. Active: false,
  762. Valid: true,
  763. Config: validAthenaConf,
  764. },
  765. },
  766. configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
  767. HelmSource: &MockKeyedConfigWatcher{
  768. Integrations: []cloudconfig.KeyedConfig{
  769. validBigQueryConf,
  770. },
  771. },
  772. ConfigFileSource: &MockKeyedConfigWatcher{
  773. Integrations: []cloudconfig.KeyedConfig{
  774. invalidAthenaConf,
  775. },
  776. },
  777. },
  778. expectedStatuses: []*Status{
  779. {
  780. Source: HelmSource,
  781. Key: validBigQueryConf.Key(),
  782. Active: true,
  783. Valid: true,
  784. Config: validBigQueryConf,
  785. },
  786. {
  787. Source: ConfigFileSource,
  788. Key: invalidAthenaConf.Key(),
  789. Active: false,
  790. Valid: false,
  791. Config: invalidAthenaConf,
  792. },
  793. },
  794. },
  795. }
  796. for name, tc := range testCases {
  797. t.Run(name, func(t *testing.T) {
  798. // Test set up and validation
  799. initialStatuses := make(map[configID]*Status)
  800. for _, status := range tc.initialStatuses {
  801. iID := configID{
  802. source: status.Source,
  803. key: status.Key,
  804. }
  805. if _, ok := initialStatuses[iID]; ok {
  806. t.Errorf("invalid test, duplicate initial status with key: %s source: %s", iID.key, iID.source.String())
  807. }
  808. initialStatuses[iID] = status
  809. }
  810. expectedStatuses := make(map[configID]*Status)
  811. for _, status := range tc.expectedStatuses {
  812. iID := configID{
  813. source: status.Source,
  814. key: status.Key,
  815. }
  816. if _, ok := expectedStatuses[iID]; ok {
  817. t.Errorf("invalid test, duplicate expected status with key: %s source: %s", iID.key, iID.source.String())
  818. }
  819. expectedStatuses[iID] = status
  820. }
  821. // Initialize controller
  822. icd := &Controller{
  823. statuses: initialStatuses,
  824. watchers: tc.configWatchers,
  825. }
  826. icd.pullWatchers()
  827. if len(icd.statuses) != len(tc.expectedStatuses) {
  828. t.Errorf("integration statueses did not have the correct length actaul: %d, expected: %d", len(icd.statuses), len(tc.expectedStatuses))
  829. }
  830. for iID, actualStatus := range icd.statuses {
  831. expectedStatus, ok := expectedStatuses[iID]
  832. if !ok {
  833. t.Errorf("expected integration statuses is missing with integration ID: %v", iID)
  834. }
  835. // failure here indicates an issue with the configID
  836. if actualStatus.Key != expectedStatus.Key {
  837. t.Errorf("integration status does not have the correct Key values actual: %s, expected: %s", actualStatus.Key, expectedStatus.Key)
  838. }
  839. // failure here indicates an issue with the configID
  840. if actualStatus.Key != expectedStatus.Key {
  841. t.Errorf("integration status does not have the correct Source values actual: %s, expected: %s", actualStatus.Source, expectedStatus.Source)
  842. }
  843. if actualStatus.Active != expectedStatus.Active {
  844. t.Errorf("integration status does not have the correct Active values actual: %v, expected: %v", actualStatus.Active, expectedStatus.Active)
  845. }
  846. if actualStatus.Valid != expectedStatus.Valid {
  847. t.Errorf("integration status does not have the correct Valid values actual: %v, expected: %v", actualStatus.Valid, expectedStatus.Valid)
  848. }
  849. if !actualStatus.Config.Equals(expectedStatus.Config) {
  850. t.Errorf("integration status does not have the correct config values actual: %v, expected: %v", actualStatus.Config, expectedStatus.Config)
  851. }
  852. }
  853. })
  854. }
  855. }