Skip to content

Commit

Permalink
Optionally replace for local dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout committed Jul 31, 2024
1 parent 2baf7f8 commit 31d3cfb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/stateful/runme/v3

go 1.22

// replace github.com/stateful/godotenv => ../godotenv

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240717164558-a6c49f84cc0f.2
github.com/Masterminds/semver/v3 v3.2.1
Expand Down
6 changes: 3 additions & 3 deletions internal/owl/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (e DatabaseUrlError) VarItem() *SetVarItem {
}

func (e DatabaseUrlError) Error() string {
return fmt.Sprintf("Error %v: The value of variable \"%s\" failed Database URL validation \"%s\" required by \"%s->%s\" declared in \"%s\"",
return fmt.Sprintf("Error %v: The value of variable \"%s\" failed DatabaseUrl validation \"%s\" required by \"%s->%s\" declared in \"%s\"",
e.Code(),
e.Key(),
e.error.Error(),
Expand Down Expand Up @@ -288,8 +288,8 @@ var ComplexDefTypes = map[string]*ComplexDef{
},
Validator: TagValidator,
},
"Database": {
Name: "Database",
"DatabaseUrl": {
Name: "DatabaseUrl",
Breaker: "DATABASE",
Items: map[string]*varSpec{
"URL": {
Expand Down
10 changes: 5 additions & 5 deletions internal/owl/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func Test_Store_ComplexWithTagValidation(t *testing.T) {
func Test_Store_ComplexWithDbUrlValidation(t *testing.T) {
t.Run("Valid", func(t *testing.T) {
fake := []byte(`GOPATH=/Users/sourishkrout/go
DATABASE_URL=postgres://platform:platform@localhost:5432/platform # Database`)
DATABASE_URL=postgres://platform:platform@localhost:5432/platform # DatabaseUrl`)
store, err := NewStore(withSpecsFile(".env.example", fake, true), WithEnvFile(".env", fake))
require.NoError(t, err)
require.NotNil(t, store)
Expand All @@ -113,7 +113,7 @@ func Test_Store_ComplexWithDbUrlValidation(t *testing.T) {

t.Run("Invalid scheme", func(t *testing.T) {
fake := []byte(`GOPATH=/Users/sourishkrout/go
DATABASE_URL=abcdef://platform:platform@localhost:5432/platform # Database`)
DATABASE_URL=abcdef://platform:platform@localhost:5432/platform # DatabaseUrl`)
store, err := NewStore(withSpecsFile(".env.example", fake, true), WithEnvFile(".env", fake))
require.NoError(t, err)
require.NotNil(t, store)
Expand All @@ -125,14 +125,14 @@ func Test_Store_ComplexWithDbUrlValidation(t *testing.T) {
assert.EqualValues(t, "DATABASE_URL", snapshot[0].Var.Key)
assert.EqualValues(t, "abc...orm", snapshot[0].Value.Resolved)
assert.EqualValues(t,
`Error 2: The value of variable "DATABASE_URL" failed Database URL validation "unknown database scheme" required by "Database->URL" declared in ".env.example"`,
`Error 2: The value of variable "DATABASE_URL" failed DatabaseUrl validation "unknown database scheme" required by "DatabaseUrl->URL" declared in ".env.example"`,
snapshot[0].Errors[0].Message,
)
})

t.Run("Invalid format", func(t *testing.T) {
fake := []byte(`GOPATH=/Users/sourishkrout/go
DATABASE_URL=this-is-not-a-database-url # Database`)
DATABASE_URL=this-is-not-a-database-url # DatabaseUrl`)
store, err := NewStore(withSpecsFile(".env.example", fake, true), WithEnvFile(".env", fake))
require.NoError(t, err)
require.NotNil(t, store)
Expand All @@ -144,7 +144,7 @@ func Test_Store_ComplexWithDbUrlValidation(t *testing.T) {
assert.EqualValues(t, "DATABASE_URL", snapshot[0].Var.Key)
assert.EqualValues(t, "thi...url", snapshot[0].Value.Resolved)
assert.EqualValues(t,
`Error 2: The value of variable "DATABASE_URL" failed Database URL validation "invalid database scheme" required by "Database->URL" declared in ".env.example"`,
`Error 2: The value of variable "DATABASE_URL" failed DatabaseUrl validation "invalid database scheme" required by "DatabaseUrl->URL" declared in ".env.example"`,
snapshot[0].Errors[0].Message,
)
})
Expand Down

0 comments on commit 31d3cfb

Please sign in to comment.