summaryrefslogtreecommitdiff
path: root/sandpit
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2017-07-15 01:26:39 +0100
committerKatolaZ <katolaz@freaknet.org>2017-07-15 01:26:39 +0100
commit726b399e4747032a3d052339cd62c57ae5b6767c (patch)
treeaac8350e83bb13e9628dd287ca3aae97ecafcb32 /sandpit
parented637037b75cb5dfe1b49e776956fa6ab3632b68 (diff)
pipeline from spool to worker is done -- added examples
Diffstat (limited to 'sandpit')
-rw-r--r--sandpit/test_parse_message.go44
-rw-r--r--sandpit/test_regexp.go26
-rw-r--r--sandpit/test_worker_cfg.go63
3 files changed, 133 insertions, 0 deletions
diff --git a/sandpit/test_parse_message.go b/sandpit/test_parse_message.go
new file mode 100644
index 0000000..f60f03c
--- /dev/null
+++ b/sandpit/test_parse_message.go
@@ -0,0 +1,44 @@
+package main
+
+import(
+ "fmt"
+ "github.com/go-yaml/yaml"
+ "io/ioutil"
+ "log"
+ "os"
+)
+
+
+var orig_msg= `
+---
+m_id: 123456
+m_repo: master
+m_branch: test_branch
+m_oldrev: a1b2c3d4e5f6
+m_newrev: 9a8b7c6d5e4f
+...
+
+`
+
+
+func main(){
+
+ var msg *SCORSHmsg
+ msg = new(SCORSHmsg)
+
+
+ fname := "spool/test_2"
+
+ data, err := ioutil.ReadFile(fname)
+ if err != nil {
+ log.Printf("Unable to open file: %s\n", fname)
+ os.Exit(1)
+ }
+ err = yaml.Unmarshal([]byte(data), msg)
+ if err != nil{
+ log.Printf("Error parsing message: %s", err)
+ }
+
+ fmt.Printf("%s\n", msg)
+
+}
diff --git a/sandpit/test_regexp.go b/sandpit/test_regexp.go
new file mode 100644
index 0000000..5ae1d88
--- /dev/null
+++ b/sandpit/test_regexp.go
@@ -0,0 +1,26 @@
+package main
+
+import(
+ "regexp"
+ "log"
+)
+
+
+func main (){
+
+ pattern := ".*"
+ str := "my_string"
+
+ matched, err := regexp.MatchString(pattern, str)
+
+ if err != nil {
+ log.Fatal("Error matching string: ", err)
+ }
+
+ if matched {
+ log.Printf("Yes! '%s' matched '%s'\n", str, pattern)
+ } else {
+ log.Printf("Bad luck!\n")
+ }
+
+}
diff --git a/sandpit/test_worker_cfg.go b/sandpit/test_worker_cfg.go
new file mode 100644
index 0000000..b8bc891
--- /dev/null
+++ b/sandpit/test_worker_cfg.go
@@ -0,0 +1,63 @@
+package main
+
+import(
+ "fmt"
+ "github.com/go-yaml/yaml"
+ "log"
+ "strings"
+)
+
+
+var worker_cfg = `
+---
+w_tags:
+ [
+ {
+ t_name: "BUILD",
+ t_keyrings: ["build_keyring.asc", "general_keyring.asc"],
+ t_commands: [
+ {
+ c_url: "file:///home/user/bin/script.sh $1 $2",
+ c_hash: "12da324fb76s924acbce"
+ },
+ {
+ c_url: "http://my.server.net/call.pl?branch=$1"
+ }
+ ]
+ },
+ {
+ t_name: "PUBLISH",
+ t_keyrings: ["web_developers.asc"],
+ t_commands: [
+ {
+ c_url: "file:///usr/local/bin/publish.py $repo $branch",
+ c_hash: "3234567898765432345678"
+ }
+ ]
+ }
+ ]
+...
+
+`
+
+
+func main(){
+
+ var w *SCORSHworker
+ w = new(SCORSHworker)
+
+
+ sep := "\n---\n"
+
+ idx := strings.Index(worker_cfg, sep)
+
+ err := yaml.Unmarshal([]byte(worker_cfg[idx:]), w)
+
+
+ if err != nil{
+ log.Printf("Error parsing message: %s", err)
+ }
+
+ fmt.Printf("%s\n", w)
+
+}