Commit eb8c20f8 authored by Boris Mühmer's avatar Boris Mühmer
Browse files

change some names to better fit purpose

parent 102df4ab
Loading
Loading
Loading
Loading
+25 −24
Original line number Diff line number Diff line
@@ -12,28 +12,29 @@ import (
type Channel uint

const (
	In  Channel = 1
	Out Channel = 2
	Err Channel = 3
	undefined Channel = iota
	In
	Out
	Err
)

type Expect struct {
	stdin           io.Reader
	stdout          io.Writer
	stderr          io.Writer
	matchStream     chan ChannelMatch
	matchStream     chan ChannelPatternValue
	terminateStream chan bool
	finishedStream  chan bool
}

type Match struct {
type PatternValue struct {
	p string
	v string
}

type ChannelMatch struct {
type ChannelPatternValue struct {
	c Channel
	m Match
	m PatternValue
}

func New() (*Expect, error) {
@@ -50,14 +51,14 @@ func New() (*Expect, error) {
	return x, nil
}

func async(c chan<- bool, b bool) {
func asyncBool(c chan<- bool, b bool) {
	go func() {
		c <- b
	}()
}

func (x *Expect) Close() error {
	async(x.terminateStream, true)
	asyncBool(x.terminateStream, true)
	<-x.finishedStream
	return nil
}
@@ -74,10 +75,10 @@ func (x *Expect) Stderr() io.Writer {
	return x.stderr
}

func (x *Expect) Wait(c Channel, match, text string) error {
	x.matchStream <- ChannelMatch{
func (x *Expect) Match(c Channel, match, text string) error {
	x.matchStream <- ChannelPatternValue{
		c: c,
		m: Match{p: match, v: text},
		m: PatternValue{p: match, v: text},
	}
	return nil
}
@@ -91,15 +92,15 @@ func (x *Expect) worker(started chan<- bool) {
	x.stdout = stdout
	x.stderr = stderr

	x.matchStream = make(chan ChannelMatch)
	x.matchStream = make(chan ChannelPatternValue)

	matchOutStream := make(chan Match)
	matchOutStream := make(chan PatternValue)
	startedOutStream := make(chan bool)
	terminateOutStream := make(chan bool)
	terminatedOutStream := make(chan bool)
	terminatedOut := false

	matchErrStream := make(chan Match)
	matchErrStream := make(chan PatternValue)
	startedErrStream := make(chan bool)
	terminateErrStream := make(chan bool)
	terminatedErrStream := make(chan bool)
@@ -115,7 +116,7 @@ func (x *Expect) worker(started chan<- bool) {
	for _, pa := range []struct {
		in               io.Reader
		startedStream    chan<- bool
		matchStream      <-chan Match
		matchStream      <-chan PatternValue
		stringStream     chan<- string
		terminateStream  <-chan bool
		terminatedStream chan<- bool
@@ -127,7 +128,7 @@ func (x *Expect) worker(started chan<- bool) {
		go func(
			in io.Reader,
			startedStream chan<- bool,
			matchStream <-chan Match,
			matchStream <-chan PatternValue,
			stringStream chan<- string,
			terminateStream <-chan bool,
			terminatedStream chan<- bool,
@@ -163,8 +164,8 @@ func (x *Expect) worker(started chan<- bool) {
			case !valid || !terminate:
				continue
			default:
				async(terminateOutStream, true)
				async(terminateErrStream, true)
				asyncBool(terminateOutStream, true)
				asyncBool(terminateErrStream, true)
			}
		case terminated, valid := <-terminatedOutStream:
			switch {
@@ -172,7 +173,7 @@ func (x *Expect) worker(started chan<- bool) {
				continue
			default:
				terminatedOut = true
				async(checkStream, true)
				asyncBool(checkStream, true)
			}
		case terminated, valid := <-terminatedErrStream:
			switch {
@@ -180,7 +181,7 @@ func (x *Expect) worker(started chan<- bool) {
				continue
			default:
				terminatedErr = true
				async(checkStream, true)
				asyncBool(checkStream, true)
			}
		case check, valid := <-checkStream:
			switch {
@@ -197,13 +198,13 @@ func (x *Expect) worker(started chan<- bool) {
func process(
	in io.Reader,
	startedStream chan<- bool,
	matchStream <-chan Match,
	matchStream <-chan PatternValue,
	stringStream chan<- string,
	terminateStream <-chan bool,
	terminatedStream chan<- bool,
) {
	defer async(terminatedStream, true)
	matches := []Match{}
	defer asyncBool(terminatedStream, true)
	matches := []PatternValue{}

	startedStream <- true

+3 −3
Original line number Diff line number Diff line
@@ -22,9 +22,9 @@ func TestPasswdChange(t *testing.T) {
	}
	defer x.Close()

	x.Wait(Err, "Current password", lp2Pass)
	x.Wait(Err, "New password", lpNPass)
	x.Wait(Err, "Retype new password", lpNPass)
	x.Match(Err, "Current password", lp2Pass)
	x.Match(Err, "New password", lpNPass)
	x.Match(Err, "Retype new password", lpNPass)

	p, err := passwd.New(x.Stdin(), x.Stdout(), x.Stderr(), lp2User)
	if err != nil {