-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add 3 tests * Add golangci-lint and fix linting errors * Add pinned go version for CI * Add checkout to CI GHA * Remove golangci-lint from CI
- Loading branch information
1 parent
0eaa83a
commit e1dbb93
Showing
7 changed files
with
140 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
ci: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
- name: Setup Go environment | ||
uses: actions/[email protected] | ||
with: | ||
go-version: ">=1.22.1" | ||
- name: Run tests | ||
run: go test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestGetDbtProfile(t *testing.T) { | ||
// Create a temporary profiles.yml file for testing | ||
tmpDir := t.TempDir() | ||
err := os.Mkdir(filepath.Join(tmpDir, ".dbt"), 0755) | ||
if err != nil { | ||
t.Fatalf("Failed to create temporary .dbt directory: %v", err) | ||
} | ||
profilesFile := filepath.Join(tmpDir, ".dbt", "profiles.yml") | ||
content := []byte(` | ||
test_profile: | ||
target: dev | ||
outputs: | ||
dev: | ||
type: snowflake | ||
account: testaccount | ||
user: testuser | ||
password: testpassword | ||
database: testdb | ||
warehouse: testwh | ||
schema: testschema | ||
`) | ||
err = os.WriteFile(profilesFile, content, 0644) | ||
if err != nil { | ||
t.Fatalf("Failed to create temporary profiles.yml file: %v", err) | ||
} | ||
|
||
os.Setenv("HOME", tmpDir) | ||
|
||
// Profile exists | ||
profile, err := GetDbtProfile("test_profile") | ||
if err != nil { | ||
t.Errorf("GetDbtProfile returned an error for an existing profile: %v", err) | ||
} | ||
if profile.Target != "dev" { | ||
t.Errorf("Expected target 'dev', got '%s'", profile.Target) | ||
} | ||
|
||
// Profile does not exist | ||
profile, err = GetDbtProfile("aragorn") | ||
if err == nil { | ||
t.Error("GetDbtProfile did not return an error for a non-existing profile") | ||
} | ||
if profile != nil { | ||
t.Error("GetDbtProfile returned a non-nil profile for a non-existing profile") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestPrepBuildDir(t *testing.T) { | ||
buildDir := "testPrepBuildDir" | ||
PrepBuildDir(buildDir) | ||
_, err := os.Stat(buildDir) | ||
if os.IsNotExist(err) { | ||
t.Errorf("PrepBuildDir did not create the directory") | ||
} | ||
os.Remove(buildDir) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"tbd/shared" | ||
"testing" | ||
) | ||
|
||
func TestWriteYAML(t *testing.T) { | ||
tablesFixture := shared.SourceTables{ | ||
SourceTables: []shared.SourceTable{ | ||
{ | ||
Name: "table1", | ||
Columns: []shared.Column{ | ||
{ | ||
Name: "column1", | ||
Description: "column1 description", | ||
DataType: "int", | ||
Tests: []string{}, | ||
}, | ||
}, | ||
DataTypeGroups: map[string][]shared.Column{ | ||
"int": { | ||
shared.Column{ | ||
Name: "column1", | ||
Description: "column1 description", | ||
DataType: "int", | ||
Tests: []string{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
buildDir := "testWriteYAML" | ||
PrepBuildDir(buildDir) | ||
WriteYAML(tablesFixture, buildDir) | ||
_, err := os.Stat(buildDir + "/_sources.yml") | ||
if os.IsNotExist(err) { | ||
t.Errorf("WriteYAML did not create the file") | ||
} | ||
err = os.RemoveAll(buildDir) | ||
if err != nil { | ||
t.Errorf("Failed to clean up test directory") | ||
} | ||
} |