bigqueryintegration_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package gcp
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestBigQueryIntegration_GetCloudCost(t *testing.T) {
  8. bqi := &BigQueryIntegration{
  9. BigQueryQuerier: BigQueryQuerier{
  10. BigQueryConfiguration: BigQueryConfiguration{
  11. ProjectID: "test-project",
  12. Dataset: "test-dataset",
  13. Table: "test-table",
  14. },
  15. },
  16. }
  17. start := time.Now().Add(-24 * time.Hour)
  18. end := time.Now()
  19. // This will fail due to missing credentials, but we can test the function structure
  20. _, err := bqi.GetCloudCost(start, end)
  21. assert.Error(t, err) // Expect error due to missing credentials
  22. }
  23. func TestBigQueryIntegration_GetWhereConjuncts(t *testing.T) {
  24. start := time.Now().Add(-24 * time.Hour)
  25. end := time.Now()
  26. // Test the GetWhereConjuncts function
  27. result := GetWhereConjuncts(start, end, true)
  28. assert.NotEmpty(t, result)
  29. assert.Len(t, result, 2)
  30. assert.Contains(t, result[0], "DATE(_PARTITIONTIME)")
  31. assert.Contains(t, result[1], "usage_start_time")
  32. }
  33. func TestBigQueryIntegration_GetFlexibleCUDRates(t *testing.T) {
  34. bqi := &BigQueryIntegration{
  35. BigQueryQuerier: BigQueryQuerier{
  36. BigQueryConfiguration: BigQueryConfiguration{
  37. ProjectID: "test-project",
  38. Dataset: "test-dataset",
  39. Table: "test-table",
  40. },
  41. },
  42. }
  43. start := time.Now().Add(-24 * time.Hour)
  44. end := time.Now()
  45. // This will fail due to missing credentials, but we can test the function structure
  46. _, err := bqi.GetFlexibleCUDRates(start, end)
  47. assert.Error(t, err) // Expect error due to missing credentials
  48. }
  49. func TestBigQueryIntegration_queryFlexibleCUDTotalCosts(t *testing.T) {
  50. bqi := &BigQueryIntegration{
  51. BigQueryQuerier: BigQueryQuerier{
  52. BigQueryConfiguration: BigQueryConfiguration{
  53. ProjectID: "test-project",
  54. Dataset: "test-dataset",
  55. Table: "test-table",
  56. },
  57. },
  58. }
  59. start := time.Now().Add(-24 * time.Hour)
  60. end := time.Now()
  61. // This will fail due to missing credentials, but we can test the function structure
  62. _, err := bqi.queryFlexibleCUDTotalCosts(start, end)
  63. assert.Error(t, err) // Expect error due to missing credentials
  64. }
  65. func TestBigQueryIntegration_queryFlexibleCUDTotalCredits(t *testing.T) {
  66. bqi := &BigQueryIntegration{
  67. BigQueryQuerier: BigQueryQuerier{
  68. BigQueryConfiguration: BigQueryConfiguration{
  69. ProjectID: "test-project",
  70. Dataset: "test-dataset",
  71. Table: "test-table",
  72. },
  73. },
  74. }
  75. start := time.Now().Add(-24 * time.Hour)
  76. end := time.Now()
  77. // This will fail due to missing credentials, but we can test the function structure
  78. _, err := bqi.queryFlexibleCUDTotalCredits(start, end)
  79. assert.Error(t, err) // Expect error due to missing credentials
  80. }