athenaconfiguration_test.go 19 KB

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