From 6032a447436ea711e05bd31f88ae24d17955f286 Mon Sep 17 00:00:00 2001
From: gwen windflower <gwenwindflower@gmail.com>
Date: Sun, 14 Apr 2024 09:33:50 -0500
Subject: [PATCH] Fix connection details test and refs to shared package

---
 generate_column_desc.go            |  3 +-
 main.go                            |  2 +-
 set_connection_details.go          | 65 ++++++++++++++++++++++--------
 set_connection_details_test.go     |  4 +-
 sourcerer/get_columns.go           |  3 +-
 sourcerer/get_conn.go              |  3 +-
 sourcerer/get_sources.go           |  3 +-
 sourcerer/put_columns_on_tables.go |  3 +-
 write_staging_models.go            |  3 +-
 write_yaml.go                      |  3 +-
 write_yaml_test.go                 |  3 +-
 11 files changed, 68 insertions(+), 27 deletions(-)

diff --git a/generate_column_desc.go b/generate_column_desc.go
index ec50db3..4d7b227 100644
--- a/generate_column_desc.go
+++ b/generate_column_desc.go
@@ -10,8 +10,9 @@ import (
 	"os"
 	"regexp"
 	"sync"
-	"tbd/shared"
 	"time"
+
+	"github.com/gwenwindflower/tbd/shared"
 )
 
 type Payload struct {
diff --git a/main.go b/main.go
index de1efd4..34bc94e 100644
--- a/main.go
+++ b/main.go
@@ -5,10 +5,10 @@ import (
 	"fmt"
 	"log"
 	"sync"
-	"tbd/sourcerer"
 	"time"
 
 	"github.com/charmbracelet/huh/spinner"
+	"github.com/gwenwindflower/tbd/sourcerer"
 )
 
 type Elapsed struct {
diff --git a/set_connection_details.go b/set_connection_details.go
index 7935492..c09777c 100644
--- a/set_connection_details.go
+++ b/set_connection_details.go
@@ -2,7 +2,8 @@ package main
 
 import (
 	"log"
-	"tbd/shared"
+
+	"github.com/gwenwindflower/tbd/shared"
 )
 
 func SetConnectionDetails(formResponse FormResponse) shared.ConnectionDetails {
@@ -12,24 +13,54 @@ func SetConnectionDetails(formResponse FormResponse) shared.ConnectionDetails {
 		if err != nil {
 			log.Fatalf("Could not get dbt profile %v\n", err)
 		}
-		connectionDetails = shared.ConnectionDetails{
-			ConnType: profile.Outputs[formResponse.DbtProfileOutput].ConnType,
-			Username: profile.Outputs[formResponse.DbtProfileOutput].User,
-			Account:  profile.Outputs[formResponse.DbtProfileOutput].Account,
-			Schema:   formResponse.Schema,
-			Database: profile.Outputs[formResponse.DbtProfileOutput].Database,
-			Project:  profile.Outputs[formResponse.DbtProfileOutput].Project,
-			Dataset:  formResponse.Schema,
+		switch profile.Outputs[formResponse.DbtProfileOutput].ConnType {
+		case "snowflake":
+			{
+				connectionDetails = shared.ConnectionDetails{
+					ConnType: profile.Outputs[formResponse.DbtProfileOutput].ConnType,
+					Username: profile.Outputs[formResponse.DbtProfileOutput].User,
+					Account:  profile.Outputs[formResponse.DbtProfileOutput].Account,
+					Database: profile.Outputs[formResponse.DbtProfileOutput].Database,
+					Schema:   formResponse.Schema,
+				}
+			}
+		case "bigquery":
+			{
+				connectionDetails = shared.ConnectionDetails{
+					ConnType: profile.Outputs[formResponse.DbtProfileOutput].ConnType,
+					Project:  profile.Outputs[formResponse.DbtProfileOutput].Project,
+					Dataset:  profile.Outputs[formResponse.DbtProfileOutput].Dataset,
+				}
+			}
+		default:
+			{
+				log.Fatalf("Unsupported connection type %v\n", profile.Outputs[formResponse.DbtProfileOutput].ConnType)
+			}
 		}
 	} else {
-		connectionDetails = shared.ConnectionDetails{
-			ConnType: formResponse.Warehouse,
-			Username: formResponse.Username,
-			Account:  formResponse.Account,
-			Schema:   formResponse.Schema,
-			Database: formResponse.Database,
-			Project:  formResponse.Project,
-			Dataset:  formResponse.Dataset,
+		switch formResponse.Warehouse {
+		case "snowflake":
+			{
+				connectionDetails = shared.ConnectionDetails{
+					ConnType: formResponse.Warehouse,
+					Username: formResponse.Username,
+					Account:  formResponse.Account,
+					Schema:   formResponse.Schema,
+					Database: formResponse.Database,
+				}
+			}
+		case "bigquery":
+			{
+				connectionDetails = shared.ConnectionDetails{
+					ConnType: formResponse.Warehouse,
+					Project:  formResponse.Project,
+					Dataset:  formResponse.Dataset,
+				}
+			}
+		default:
+			{
+				log.Fatalf("Unsupported connection type %v\n", formResponse.Warehouse)
+			}
 		}
 	}
 	return connectionDetails
diff --git a/set_connection_details_test.go b/set_connection_details_test.go
index 62451cb..9af2eaf 100644
--- a/set_connection_details_test.go
+++ b/set_connection_details_test.go
@@ -2,8 +2,9 @@ package main
 
 import (
 	"os"
-	"tbd/shared"
 	"testing"
+
+	"github.com/gwenwindflower/tbd/shared"
 )
 
 func TestSetConnectionDetailsWithoutDbtProfile(t *testing.T) {
@@ -39,6 +40,7 @@ func TestSetConnectionDetailsWithDbtProfile(t *testing.T) {
 		UseDbtProfile:        true,
 		DbtProfile:           "elf",
 		DbtProfileOutput:     "dev",
+		Schema:               "hall_of_thranduil",
 		GenerateDescriptions: false,
 		BuildDir:             "test_build",
 		Confirm:              true,
diff --git a/sourcerer/get_columns.go b/sourcerer/get_columns.go
index 5cd6899..7b5e31e 100644
--- a/sourcerer/get_columns.go
+++ b/sourcerer/get_columns.go
@@ -4,7 +4,8 @@ import (
 	"context"
 	"fmt"
 	"log"
-	"tbd/shared"
+
+	"github.com/gwenwindflower/tbd/shared"
 
 	"cloud.google.com/go/bigquery"
 	"google.golang.org/api/iterator"
diff --git a/sourcerer/get_conn.go b/sourcerer/get_conn.go
index 41912b7..9ba603a 100644
--- a/sourcerer/get_conn.go
+++ b/sourcerer/get_conn.go
@@ -5,7 +5,8 @@ import (
 	"database/sql"
 	"errors"
 	"strings"
-	"tbd/shared"
+
+	"github.com/gwenwindflower/tbd/shared"
 
 	"cloud.google.com/go/bigquery"
 )
diff --git a/sourcerer/get_sources.go b/sourcerer/get_sources.go
index f6822ee..384911b 100644
--- a/sourcerer/get_sources.go
+++ b/sourcerer/get_sources.go
@@ -4,7 +4,8 @@ import (
 	"context"
 	"fmt"
 	"log"
-	"tbd/shared"
+
+	"github.com/gwenwindflower/tbd/shared"
 
 	"google.golang.org/api/iterator"
 )
diff --git a/sourcerer/put_columns_on_tables.go b/sourcerer/put_columns_on_tables.go
index 7073e34..98d8afa 100644
--- a/sourcerer/put_columns_on_tables.go
+++ b/sourcerer/put_columns_on_tables.go
@@ -6,7 +6,8 @@ import (
 	"log"
 	"regexp"
 	"sync"
-	"tbd/shared"
+
+	"github.com/gwenwindflower/tbd/shared"
 )
 
 func (sfc *SfConn) PutColumnsOnTables(ctx context.Context, tables shared.SourceTables) {
diff --git a/write_staging_models.go b/write_staging_models.go
index 5cdc5cd..03b437e 100644
--- a/write_staging_models.go
+++ b/write_staging_models.go
@@ -7,8 +7,9 @@ import (
 	"os"
 	"strings"
 	"sync"
-	"tbd/shared"
 	"text/template"
+
+	"github.com/gwenwindflower/tbd/shared"
 )
 
 //go:embed *.sql
diff --git a/write_yaml.go b/write_yaml.go
index 1d1b95b..93cf28c 100644
--- a/write_yaml.go
+++ b/write_yaml.go
@@ -3,7 +3,8 @@ package main
 import (
 	"log"
 	"os"
-	"tbd/shared"
+
+	"github.com/gwenwindflower/tbd/shared"
 
 	"gopkg.in/yaml.v2"
 )
diff --git a/write_yaml_test.go b/write_yaml_test.go
index e773ade..a72844d 100644
--- a/write_yaml_test.go
+++ b/write_yaml_test.go
@@ -2,8 +2,9 @@ package main
 
 import (
 	"os"
-	"tbd/shared"
 	"testing"
+
+	"github.com/gwenwindflower/tbd/shared"
 )
 
 func TestWriteYAML(t *testing.T) {