-
Notifications
You must be signed in to change notification settings - Fork 415
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
1 parent
e46bea5
commit 95161a2
Showing
34 changed files
with
188 additions
and
235 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
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,4 @@ | ||
validation_cmd: "docker-compose up" | ||
teardown_cmd: "docker-compose down" | ||
timeout: 30 | ||
expected_output: "beers ordered to room 3" |
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,4 @@ | ||
validation_cmd: "docker-compose up" | ||
teardown_cmd: "docker-compose down" | ||
timeout: 30 | ||
expected_output: "Starting handler" |
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,4 @@ | ||
validation_cmd: "docker-compose up" | ||
teardown_cmd: "docker-compose down" | ||
timeout: 60 | ||
expected_output: "POST /foo_or_bar: message" |
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,4 @@ | ||
validation_cmd: "docker-compose up" | ||
teardown_cmd: "docker-compose down" | ||
timeout: 60 | ||
expected_output: "msg=\"Message acked\"" |
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,4 @@ | ||
validation_cmd: "docker-compose up" | ||
teardown_cmd: "docker-compose down" | ||
timeout: 60 | ||
expected_output: "msg=\"Message sent to Kafka\"" |
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,4 @@ | ||
validation_cmd: "docker-compose up" | ||
teardown_cmd: "docker-compose down" | ||
timeout: 60 | ||
expected_output: "msg=\"Starting handler\"" |
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,4 @@ | ||
validation_cmd: "docker-compose up" | ||
teardown_cmd: "docker-compose down" | ||
timeout: 60 | ||
expected_output: "received event [0-9]+" |
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,5 @@ | ||
module github.com/ThreeDotsLabs/watermill/dev/validate-examples | ||
|
||
go 1.12 | ||
|
||
require gopkg.in/yaml.v2 v2.2.2 // indirect |
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,3 @@ | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
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,122 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
"time" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
type Config struct { | ||
ValidationCmd string `yaml:"validation_cmd"` | ||
TeardownCmd string `yaml:"teardown_cmd"` | ||
Timeout int `yaml:"timeout"` | ||
ExpectedOutput string `yaml:"expected_output"` | ||
} | ||
|
||
func (c *Config) LoadFrom(path string) error { | ||
file, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
err = yaml.Unmarshal(file, c) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func main() { | ||
walkErr := filepath.Walk(".", func(exampleConfig string, f os.FileInfo, _ error) error { | ||
matches, _ := filepath.Match(".validate_example*.yml", f.Name()) | ||
if !matches { | ||
return nil | ||
} | ||
|
||
exampleDirectory := filepath.Dir(exampleConfig) | ||
ok, err := validate(exampleConfig) | ||
|
||
if err != nil { | ||
fmt.Printf("validation for %s failed, err: %v\n", exampleDirectory, err) | ||
return nil | ||
} | ||
|
||
if ok { | ||
fmt.Printf("validation for %s succeeded\n", exampleDirectory) | ||
return nil | ||
} | ||
|
||
fmt.Printf("validation for %s failed\n", exampleDirectory) | ||
return nil | ||
}) | ||
if walkErr != nil { | ||
panic(walkErr) | ||
} | ||
|
||
} | ||
|
||
func validate(path string) (bool, error) { | ||
config := &Config{} | ||
err := config.LoadFrom(path) | ||
if err != nil { | ||
return false, fmt.Errorf("could not load config, err: %v", err) | ||
} | ||
|
||
cmdAndArgs := strings.Fields(config.ValidationCmd) | ||
validationCmd := exec.Command(cmdAndArgs[0], cmdAndArgs[1:]...) | ||
validationCmd.Dir = filepath.Dir(path) | ||
defer func() { | ||
if config.TeardownCmd == "" { | ||
return | ||
} | ||
cmdAndArgs := strings.Fields(config.TeardownCmd) | ||
teardownCmd := exec.Command(cmdAndArgs[0], cmdAndArgs[1:]...) | ||
teardownCmd.Dir = filepath.Dir(path) | ||
_ = teardownCmd.Run() | ||
}() | ||
|
||
stdout, err := validationCmd.StdoutPipe() | ||
if err != nil { | ||
return false, fmt.Errorf("could not attach to stdout, err: %v", err) | ||
} | ||
|
||
err = validationCmd.Start() | ||
if err != nil { | ||
return false, fmt.Errorf("could not start validation, err: %v", err) | ||
} | ||
|
||
success := make(chan bool) | ||
|
||
go func() { | ||
output := bufio.NewReader(stdout) | ||
for { | ||
line, _, err := output.ReadLine() | ||
if err != nil { | ||
if err == io.EOF { | ||
break | ||
} | ||
} | ||
ok, _ := regexp.Match(config.ExpectedOutput, line) | ||
if ok { | ||
success <- true | ||
return | ||
} | ||
} | ||
success <- false | ||
}() | ||
|
||
select { | ||
case success := <-success: | ||
return success, nil | ||
case <-time.After(time.Duration(config.Timeout) * time.Second): | ||
return false, fmt.Errorf("validation command timed out") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
validation_cmd: "docker-compose up" | ||
teardown_cmd: "docker-compose down" | ||
timeout: 30 | ||
expected_output: "received message: [0-9a-f\\-]+, payload: Hello, world!" |
8 changes: 0 additions & 8 deletions
8
docs/content/docs/getting-started/go-channel/.validate_example.sh
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
docs/content/docs/getting-started/go-channel/.validate_example.yml
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,3 @@ | ||
validation_cmd: "docker-compose up" | ||
timeout: 1 | ||
expected_output: "payload: Hello, world!" |
8 changes: 0 additions & 8 deletions
8
docs/content/docs/getting-started/googlecloud/.validate_example.sh
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.