-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
315 additions
and
125 deletions.
There are no files selected for viewing
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
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
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,13 @@ | ||
package krab | ||
|
||
import ( | ||
"github.com/hashicorp/hcl/v2" | ||
"github.com/zclconf/go-cty/cty" | ||
) | ||
|
||
// Do subtype for other types. | ||
type Do struct { | ||
Action hcl.Expression `hcl:"action,optional"` | ||
Inputs map[string]cty.Value `hcl:"inputs,optional"` | ||
SQL string `hcl:"sql,optional"` | ||
} |
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,48 @@ | ||
package krab | ||
|
||
import ( | ||
"github.com/ohkrab/krab/krabhcl" | ||
) | ||
|
||
// TestExample represents test runner configuration. | ||
// | ||
type TestExample struct { | ||
TestSuiteRefName string `hcl:"test_suite,label"` | ||
Name string `hcl:"name,label"` | ||
Its []*TestExampleIt `hcl:"it,block"` | ||
} | ||
|
||
func (t *TestExample) Addr() krabhcl.Addr { | ||
return krabhcl.Addr{Keyword: "test", Labels: []string{t.TestSuiteRefName, t.Name}} | ||
} | ||
|
||
func (t *TestExample) Validate() error { | ||
return ErrorCoalesce( | ||
ValidateRefName(t.TestSuiteRefName), | ||
) | ||
} | ||
|
||
// TestExampleIt represents one use case for test example that contain assertions. | ||
type TestExampleIt struct { | ||
Comment string `hcl:"comment,label"` | ||
Do *Do `hcl:"do,block"` | ||
RowAsserts []*AssertRow `hcl:"row,block"` | ||
RowsAsserts []*AssertRows `hcl:"rows,block"` | ||
} | ||
|
||
// AssertRows | ||
type AssertRows struct { | ||
Expectations []*Expect `hcl:"expect,block"` | ||
} | ||
|
||
// AssertRow | ||
type AssertRow struct { | ||
Scope string `hcl:"scope,label"` | ||
Expectations []*Expect `hcl:"expect,block"` | ||
} | ||
|
||
// Expect | ||
type Expect struct { | ||
Subject string `hcl:"subject,label"` | ||
Equal *string `hcl:"equal,optional"` | ||
} |
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,26 @@ | ||
package krab | ||
|
||
import ( | ||
"github.com/ohkrab/krab/krabhcl" | ||
) | ||
|
||
// TestSuite represents test runner configuration. | ||
// | ||
type TestSuite struct { | ||
RefName string `hcl:"ref_name,label"` | ||
Before []*TestSuiteBefore `hcl:"before,block"` | ||
} | ||
|
||
func (t *TestSuite) Addr() krabhcl.Addr { | ||
return krabhcl.Addr{Keyword: "test_suite", Labels: []string{t.RefName}} | ||
} | ||
|
||
func (t *TestSuite) Validate() error { | ||
return ErrorCoalesce( | ||
ValidateRefName(t.RefName), | ||
) | ||
} | ||
|
||
type TestSuiteBefore struct { | ||
Dos []*Do `hcl:"do,block"` | ||
} |
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,44 @@ | ||
migration "create_animals" { | ||
version = "v1" | ||
|
||
up { sql = "CREATE TABLE animals(name VARCHAR)" } | ||
down { sql = "DROP TABLE animals" } | ||
} | ||
|
||
migration "create_animals_view" { | ||
version = "v2" | ||
|
||
up { sql = "CREATE MATERIALIZED VIEW anims AS SELECT name FROM animals" } | ||
down { sql = "DROP MATERIALIZED VIEW anims" } | ||
} | ||
|
||
migration "seed_animals" { | ||
version = "v3" | ||
|
||
up { sql = "INSERT INTO animals(name) VALUES('Elephant'),('Turtle'),('Cat')" } | ||
down { sql = "TRUNCATE animals" } | ||
} | ||
|
||
migration_set "animals" { | ||
arguments { | ||
arg "name" { | ||
description = "Materialized view to be refreshed" | ||
} | ||
} | ||
|
||
migrations = [ | ||
migration.create_animals, | ||
migration.create_animals_view, | ||
migration.seed_animals, | ||
] | ||
} | ||
|
||
action "view" "refresh" { | ||
arguments { | ||
arg "name" { | ||
description = "Materialized view to be refreshed" | ||
} | ||
} | ||
|
||
sql = "REFRESH MATERIALIZED VIEW {{ .Args.name | quote_ident }}" | ||
} |
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 |
---|---|---|
@@ -1,13 +1,24 @@ | ||
connection "main" { | ||
uri = "postgres://localhost:5432/krab_test" | ||
globals { | ||
uri = "global_var" | ||
} | ||
|
||
connection "default" { | ||
uri = "postgres://krab:secret@localhost:5432/postgres" | ||
} | ||
|
||
connection "interpolated" { | ||
uri = "postgres://${env("USER")}:${env("PASSWORD")}@localhost:5432/postgres" | ||
} | ||
|
||
connection "referenced" { | ||
uri = global.uri | ||
} | ||
|
||
connection "duplicated" { | ||
uri = connection.default.uri | ||
} | ||
|
||
# TODO: later | ||
# connection_pool "main" { | ||
# connections = [ | ||
# connection.main, | ||
# ] | ||
connection "from_env" { | ||
uri = env("PG_URI") | ||
} | ||
|
||
# pool = 5 | ||
# } |
File renamed without changes.
Oops, something went wrong.