mirror of
https://github.com/pushbits/server.git
synced 2025-08-01 23:59:06 +02:00
add tests for config
This commit is contained in:
parent
d39e2ea9a4
commit
e87f775b1d
11 changed files with 461 additions and 6 deletions
43
tests/mockups/config.go
Normal file
43
tests/mockups/config.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package mockups
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/pushbits/server/internal/configuration"
|
||||
)
|
||||
|
||||
// ReadConfig copies the given filename to the current folder and parses it as a config file. RemoveFile indicates whether to remove the copied file or not
|
||||
func ReadConfig(filename string, removeFile bool) (config *configuration.Configuration, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Println(r)
|
||||
err = errors.New("Paniced while reading config")
|
||||
}
|
||||
}()
|
||||
|
||||
if filename == "" {
|
||||
return nil, errors.New("Empty filename")
|
||||
}
|
||||
|
||||
file, err := ioutil.ReadFile(filename)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile("config.yml", file, 0644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config = configuration.Get()
|
||||
|
||||
if removeFile {
|
||||
os.Remove("config.yml")
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue