disabling cache; it's not really necessary.
This commit is contained in:
88
tunnelbroker/funcs_test.go
Normal file
88
tunnelbroker/funcs_test.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package tunnelbroker
|
||||
|
||||
import (
|
||||
`encoding/json`
|
||||
`fmt`
|
||||
`os`
|
||||
`strconv`
|
||||
"testing"
|
||||
|
||||
`r00t2.io/gobroke/conf`
|
||||
`r00t2.io/gobroke/tplCmd`
|
||||
`r00t2.io/gobroke/version`
|
||||
`r00t2.io/sysutils/envs`
|
||||
)
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
var err error
|
||||
var s string
|
||||
var b []byte
|
||||
var tun *Tunnel
|
||||
var u64 uint64
|
||||
var updated bool
|
||||
var tuncfg *conf.Tunnel = &conf.Tunnel{
|
||||
TunnelID: 0,
|
||||
ExplicitAddr: nil,
|
||||
MTU: 1480,
|
||||
Username: nil,
|
||||
UpdateKey: "",
|
||||
TemplateConfigs: nil,
|
||||
Cmds: []tplCmd.TemplateCmd{
|
||||
tplCmd.TemplateCmd{
|
||||
Cmd: &tplCmd.Cmd{
|
||||
Program: "echo",
|
||||
Args: []string{
|
||||
"updated {{ .TunnelID }}",
|
||||
},
|
||||
IsolateEnv: false,
|
||||
EnvVars: nil,
|
||||
OnChanges: nil,
|
||||
},
|
||||
IsTemplate: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if version.Ver, err = version.Version(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !envs.HasEnv("GOBROKE_TUNID") {
|
||||
t.Fatal("GOBROKE_TUNID not set")
|
||||
} else {
|
||||
s = os.Getenv("GOBROKE_TUNID")
|
||||
if u64, err = strconv.ParseUint(s, 10, 64); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tuncfg.TunnelID = uint(u64)
|
||||
}
|
||||
if !envs.HasEnv("GOBROKE_USERNAME") {
|
||||
t.Fatal("GOBROKE_USERNAME not set")
|
||||
} else {
|
||||
tuncfg.Username = new(string)
|
||||
*tuncfg.Username = os.Getenv("GOBROKE_USERNAME")
|
||||
}
|
||||
if !envs.HasEnv("GOBROKE_KEY") {
|
||||
t.Fatal("GOBROKE_KEY not set")
|
||||
} else {
|
||||
tuncfg.UpdateKey = os.Getenv("GOBROKE_KEY")
|
||||
}
|
||||
|
||||
if tun, err = GetTunnel(tuncfg, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if b, err = json.MarshalIndent(tun, "", " "); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("BEFORE UPDATE:\n%s\n", string(b))
|
||||
if updated, err = tun.Update(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("Updated:\t%v\n", updated)
|
||||
if b, err = json.MarshalIndent(tun, "", " "); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// spew.Dump(tun)
|
||||
fmt.Printf("AFTER UPDATE:\n%s\n", string(b))
|
||||
}
|
||||
Reference in New Issue
Block a user