Documentation
¶
Index ¶
- func Abs(path ...string) string
- func CompareFiles(a, b string) booldeprecated
- func InitTestdata()deprecated
- func Pwd() stringdeprecated
- func Read(file string) []bytedeprecated
- func ReadJSON(file string, out any)deprecated
- func ReadStr(file string) stringdeprecated
- func ReadYAML(file string, out any)deprecated
- type Testdata
- func (t *Testdata) Abs(path ...string) string
- func (t *Testdata) CompareFiles(a, b string) bool
- func (t *Testdata) Pwd() string
- func (t *Testdata) Read(file string) []byte
- func (t *Testdata) ReadJSON(file string, out any)
- func (t *Testdata) ReadStr(file string) string
- func (t *Testdata) ReadYAML(file string, out any)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareFiles
deprecated
compare content o files, function returns true if they're matching, otherwise it returns false.
the a and b are relative paths to need to temporary testdata directory
The false is returned also when any error occurs.
The function isn't optimal but it serves only for testing purposes
Deprecated: use Testdata.CompareFiles() instead
Example ¶
InitTestdata() fmt.Println(CompareFiles("compare/f1.txt", "compare/f2.txt")) fmt.Println(CompareFiles("compare/f1.txt", "compare/f3.txt"))
Output: true false
func InitTestdata
deprecated
added in
v0.4.0
func InitTestdata()
function do a copy of your './testdata' folder to temporary directory. This function ensure idempotency of tests
Deprecated: this function is deprecated and you should use Init()
func ReadJSON
deprecated
function load JSON file and fill the data into given out
Deprecated: use Testdata.ReadJSON() instead
Example ¶
Init(nil) book := struct { Title string `json:"title"` Pages int `json:"pages"` }{} ReadJSON("folder/subfolder/book.json", &book) fmt.Println(book.Title) fmt.Println(book.Pages)
Output: The Mythical Man-Month 272
func ReadStr
deprecated
returns you file body as string. If file cannot be read or it doesn't exits, then this function gives you empty string
Deprecated: use Testdata.ReadStr() instead
Example ¶
Init(nil) helloworld := ReadStr("folder/subfolder/helloworld.txt") fmt.Println(helloworld)
Output: Testdata
func ReadYAML
deprecated
function load YAML file and fill the data into given out
Deprecated: use Testdata.ReadYAML() instead
Example ¶
Init(nil) book := struct { Title string `yaml:"title"` Pages int `yaml:"pages"` }{} ReadYAML("folder/subfolder/book.yaml", &book) fmt.Println(book.Title) fmt.Println(book.Pages)
Output: The Mythical Man-Month 272
Types ¶
type Testdata ¶ added in v0.5.0
func Init ¶ added in v0.5.0
function do a copy of your './testdata' folder to temporary directory and returns you instance for test
This function ensure idempotency of tests
func (*Testdata) Abs ¶ added in v0.5.0
returns you absolute path to given path in temporary directory.
func (*Testdata) CompareFiles ¶ added in v0.5.0
compare content o files, function returns true if they're matching, otherwise it returns false.
the a and b are relative paths to need to temporary testdata directory
The false is returned also when any error occurs.
The function isn't optimal but it serves only for testing purposes
func (*Testdata) Pwd ¶ added in v0.5.0
Print working dir. In this case it will print root of temp directory
func (*Testdata) Read ¶ added in v0.5.0
returns you file body as []byte. If file cannot be read or it doesn't exits, then this function gives you empty byte array
func (*Testdata) ReadJSON ¶ added in v0.5.0
function load YAML file and fill the data into given out