-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstub.go
47 lines (39 loc) · 952 Bytes
/
stub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package gobmock
import "fmt"
// Produces an bash function with a given name.
// The function will silently consume any input
// passed in via STDIN.
func Stub(name string) Gob {
return &stub{
name: name,
shouldSkipReading: false,
}
}
type stub struct {
name string
shouldSkipReading bool
}
func (s *stub) MockContents() string {
return s.stubFunction() + s.stubExport()
}
// Produces a stub with the reading portion disabled.
// It will not consume any data passed into it via STDIN.
func (s *stub) WithoutReading() Gob {
return &stub{
name: s.name,
shouldSkipReading: true,
}
}
func (s *stub) stubExport() string {
return fmt.Sprintf(exportDefinition, s.name)
}
func (s *stub) stubFunction() string {
script := scriptStart + s.stubDefinition() + scriptEnd
return fmt.Sprintf(script, s.name)
}
func (s *stub) stubDefinition() string {
if s.shouldSkipReading {
return "# Empty stub"
}
return stubDefinition
}