Loading get.go 0 → 100644 +65 −0 Original line number Diff line number Diff line package get import ( "bytes" "fmt" "io" ) type Channel uint const ( In Channel = 1 Out Channel = 2 Err Channel = 3 ) type Expect struct { stdin bytes.Buffer stdout bytes.Buffer stderr bytes.Buffer matches []Match } type Match struct { c Channel p string v string } func New() (*Expect, error) { x := &Expect{ matches: []Match{}, } return x, nil } func (x *Expect) Close() error { return nil } func (x *Expect) Stdin() io.Reader { return &x.stdin } func (x *Expect) Stdout() io.Writer { return &x.stdout } func (x *Expect) Stderr() io.Writer { return &x.stderr } func (x *Expect) Wait(c Channel, match, text string) error { x.matches = append(x.matches, Match{ c: c, p: match, v: text, }) // dummy implementation x.stdin.WriteString(fmt.Sprintln(text)) return nil } get_test.go 0 → 100644 +35 −0 Original line number Diff line number Diff line package get import ( "testing" "repositories.muehmer.net/bsmrgo/get/mock/passwd" ) const ( lp1User = "user1" lp1Pass = "pass1" lpNPass = "#S3cr3T!" lpXPass = "wr0ng" ) func TestPasswdChange(t *testing.T) { x, err := New() if err != nil { t.Fatalf("New() failed with: %s", err) } defer x.Close() x.Wait(Err, "Current password", lp1Pass) x.Wait(Err, "New password", lpNPass) x.Wait(Err, "Retype new password", lpNPass) p, err := passwd.New(x.Stdin(), x.Stdout(), x.Stderr(), lp1User) if err != nil { t.Fatalf("New() failed with: %s", err) } if err := p.Run(); err != nil { t.Fatalf("p.Run() failed with: %s", err) } } Loading
get.go 0 → 100644 +65 −0 Original line number Diff line number Diff line package get import ( "bytes" "fmt" "io" ) type Channel uint const ( In Channel = 1 Out Channel = 2 Err Channel = 3 ) type Expect struct { stdin bytes.Buffer stdout bytes.Buffer stderr bytes.Buffer matches []Match } type Match struct { c Channel p string v string } func New() (*Expect, error) { x := &Expect{ matches: []Match{}, } return x, nil } func (x *Expect) Close() error { return nil } func (x *Expect) Stdin() io.Reader { return &x.stdin } func (x *Expect) Stdout() io.Writer { return &x.stdout } func (x *Expect) Stderr() io.Writer { return &x.stderr } func (x *Expect) Wait(c Channel, match, text string) error { x.matches = append(x.matches, Match{ c: c, p: match, v: text, }) // dummy implementation x.stdin.WriteString(fmt.Sprintln(text)) return nil }
get_test.go 0 → 100644 +35 −0 Original line number Diff line number Diff line package get import ( "testing" "repositories.muehmer.net/bsmrgo/get/mock/passwd" ) const ( lp1User = "user1" lp1Pass = "pass1" lpNPass = "#S3cr3T!" lpXPass = "wr0ng" ) func TestPasswdChange(t *testing.T) { x, err := New() if err != nil { t.Fatalf("New() failed with: %s", err) } defer x.Close() x.Wait(Err, "Current password", lp1Pass) x.Wait(Err, "New password", lpNPass) x.Wait(Err, "Retype new password", lpNPass) p, err := passwd.New(x.Stdin(), x.Stdout(), x.Stderr(), lp1User) if err != nil { t.Fatalf("New() failed with: %s", err) } if err := p.Run(); err != nil { t.Fatalf("p.Run() failed with: %s", err) } }