obsolete tests

lint-refactor
KatolaZ 8 years ago
parent 7df9111d9f
commit 5afd126a07
  1. 88
      sandpit/test_yaml.go

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/go-yaml/yaml" "github.com/go-yaml/yaml"
"log" "log"
"strings"
) )
type STag struct { type STag struct {
@ -31,18 +32,25 @@ type SCORSHcfg struct {
var msg_str = ` var msg_str = `
s_msg: s_msg:
- s_tag: BUILD [
s_args: { s_tag: BUILD,
- suites/jessie s_args: [ suites/jessie, suites/ascii]
- suites/ascii },
- s_tag: REMOVE {
s_args: s_tag: REMOVE,
- file1 s_args: [file1]
- s_tag: CUSTOM },
{
s_tag: CUSTOM,
s_args: [first, second, third] s_args: [first, second, third]
}
]
` `
var other_msg = ` var other_msg = `
this is my comment...
---
s_msg: [ s_msg: [
{s_tag: "BUILD", s_args: [suites/jessie, suites/ascii]}, {s_tag: "BUILD", s_args: [suites/jessie, suites/ascii]},
{s_tag: "REMOVE", s_args: [file1]}, {s_tag: "REMOVE", s_args: [file1]},
@ -50,8 +58,9 @@ s_msg: [
] ]
` `
var cfg_str = ` var cfg_str = `
some stuff
---
s_cfg: s_cfg:
- s_tag: BUILD - s_tag: BUILD
s_commands: s_commands:
@ -69,6 +78,7 @@ s_cfg:
{s_cmd: "file:///home/user/script/sh", s_hash: "1234567890abcdef"}, {s_cmd: "file:///home/user/script/sh", s_hash: "1234567890abcdef"},
{s_cmd: "http://my.server.net/submit.php", s_hash: "0987654321abce"} {s_cmd: "http://my.server.net/submit.php", s_hash: "0987654321abce"}
] ]
...
` `
func main() { func main() {
@ -77,42 +87,52 @@ func main() {
var conf SCORSHcfg var conf SCORSHcfg
sep := "\n---\n"
//log.Printf("%s\n", test_str) //log.Printf("%s\n", test_str)
err := yaml.Unmarshal([]byte(other_msg), &c) scorsh_idx := strings.Index(other_msg, sep)
if err != nil { if scorsh_idx >= 0 {
log.Fatal("error: ", err)
}
for _, item := range c.S_msg { err := yaml.Unmarshal([]byte(other_msg[scorsh_idx:]), &c)
fmt.Printf("Record: \n")
fmt.Printf(" s_tag: %s\n", item.S_tag)
fmt.Printf(" s_args:\n")
for _, a := range item.S_args { if err != nil {
fmt.Printf(" %s\n", a) log.Fatal("error: ", err)
} }
}
fmt.Println("----------------------------") for _, item := range c.S_msg {
fmt.Printf("Record: \n")
fmt.Printf(" s_tag: %s\n", item.S_tag)
fmt.Printf(" s_args:\n")
err = yaml.Unmarshal([]byte(cfg_str), &conf) for _, a := range item.S_args {
if err != nil { fmt.Printf(" %s\n", a)
log.Fatal("error: ", err) }
}
} }
for _, cfg_item := range conf.S_cfg { fmt.Println("----------------------------")
fmt.Printf("Config record:\n")
fmt.Printf(" s_tag: %s\n", cfg_item.S_tag) scorsh_idx = strings.Index(cfg_str, sep)
fmt.Printf(" s_commands:\n") if scorsh_idx >= 0 {
for _, c := range cfg_item.S_commands { err := yaml.Unmarshal([]byte(cfg_str[scorsh_idx:]), &conf)
fmt.Printf(" s_cmd: %s\n", c.S_cmd) if err != nil {
fmt.Printf(" s_hash: %s\n", c.S_hash) log.Fatal("error: ", err)
fmt.Println(" ---")
} }
fmt.Println("-+-+-")
} for _, cfg_item := range conf.S_cfg {
fmt.Printf("Config record:\n")
fmt.Printf(" s_tag: %s\n", cfg_item.S_tag)
fmt.Printf(" s_commands:\n")
for _, c := range cfg_item.S_commands {
fmt.Printf(" s_cmd: %s\n", c.S_cmd)
fmt.Printf(" s_hash: %s\n", c.S_hash)
fmt.Println(" ---")
}
fmt.Println("-+-+-")
}
}
} }

Loading…
Cancel
Save