2018-08-13 23:40:41 +00:00
|
|
|
package mcfg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
. "testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/mediocregopher/mediocre-go-lib/mtest/mchk"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSourceEnv(t *T) {
|
|
|
|
type state struct {
|
|
|
|
srcCommonState
|
2019-04-04 14:57:37 +00:00
|
|
|
*SourceEnv
|
2018-08-13 23:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type params struct {
|
|
|
|
srcCommonParams
|
|
|
|
}
|
|
|
|
|
|
|
|
chk := mchk.Checker{
|
|
|
|
Init: func() mchk.State {
|
|
|
|
var s state
|
|
|
|
s.srcCommonState = newSrcCommonState()
|
2019-04-04 14:57:37 +00:00
|
|
|
s.SourceEnv = &SourceEnv{
|
|
|
|
Env: make([]string, 0, 16),
|
|
|
|
}
|
2018-08-13 23:40:41 +00:00
|
|
|
return s
|
|
|
|
},
|
|
|
|
Next: func(ss mchk.State) mchk.Action {
|
|
|
|
s := ss.(state)
|
|
|
|
var p params
|
|
|
|
p.srcCommonParams = s.srcCommonState.next()
|
|
|
|
return mchk.Action{Params: p}
|
|
|
|
},
|
|
|
|
Apply: func(ss mchk.State, a mchk.Action) (mchk.State, error) {
|
|
|
|
s := ss.(state)
|
|
|
|
p := a.Params.(params)
|
2019-06-15 22:45:53 +00:00
|
|
|
s.srcCommonState = s.srcCommonState.applyCmpAndPV(p.srcCommonParams)
|
2018-08-13 23:40:41 +00:00
|
|
|
if !p.unset {
|
2019-06-15 22:45:53 +00:00
|
|
|
kv := strings.Join(append(p.cmp.Path(), p.name), "_")
|
2018-08-13 23:40:41 +00:00
|
|
|
kv = strings.Replace(kv, "-", "_", -1)
|
|
|
|
kv = strings.ToUpper(kv)
|
|
|
|
kv += "="
|
|
|
|
if p.isBool {
|
|
|
|
kv += "1"
|
|
|
|
} else {
|
|
|
|
kv += p.nonBoolVal
|
|
|
|
}
|
|
|
|
s.SourceEnv.Env = append(s.SourceEnv.Env, kv)
|
|
|
|
}
|
|
|
|
err := s.srcCommonState.assert(s.SourceEnv)
|
|
|
|
return s, err
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := chk.RunFor(2 * time.Second); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|