mirror of
https://github.com/pushbits/server.git
synced 2025-05-25 14:56:34 +02:00
move to separate config file for testing
This commit is contained in:
parent
d764733b59
commit
4e01354c90
4 changed files with 15 additions and 9 deletions
|
@ -192,8 +192,8 @@ To execute a single test use the `-run` flag.
|
|||
go test -run "TestApi_getUser"
|
||||
```
|
||||
|
||||
Running tests for all PushBits module is done by the `execute_tests.sh` script provided.
|
||||
Running tests for all PushBits module is done like this:
|
||||
|
||||
```bash
|
||||
bash execute_tests.sh
|
||||
make test
|
||||
```
|
|
@ -1 +0,0 @@
|
|||
find . -name '*.go' -printf '%h\n' | sort -u | xargs -n1 -P1 go test -cover
|
|
@ -4,6 +4,9 @@ import (
|
|||
"github.com/jinzhu/configor"
|
||||
)
|
||||
|
||||
// testMode indicates if the package is run in test mode
|
||||
var testMode bool
|
||||
|
||||
// Argon2Config holds the parameters used for creating hashes with Argon2.
|
||||
type Argon2Config struct {
|
||||
Memory uint32 `default:"131072"`
|
||||
|
@ -55,6 +58,9 @@ type Configuration struct {
|
|||
}
|
||||
|
||||
func configFiles() []string {
|
||||
if testMode {
|
||||
return []string{"config_unittest.yml"}
|
||||
}
|
||||
return []string{"config.yml"}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ type Pair struct {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
testMode = true
|
||||
m.Run()
|
||||
cleanUp()
|
||||
os.Exit(0)
|
||||
|
@ -145,7 +146,7 @@ func writeMinimalConfig() error {
|
|||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile("config.yml", configString, 0644)
|
||||
return ioutil.WriteFile("config_unittest.yml", configString, 0644)
|
||||
}
|
||||
|
||||
// Writes a config with default values to config.yml
|
||||
|
@ -159,7 +160,7 @@ func writeValidConfig() error {
|
|||
Environment: "production",
|
||||
ENVPrefix: "PUSHBITS",
|
||||
ErrorOnUnmatchedKeys: true,
|
||||
}).Load(config, "config.yml")
|
||||
}).Load(config, "config_unittest.yml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -173,13 +174,13 @@ func writeValidConfig() error {
|
|||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile("config.yml", configString, 0644)
|
||||
return ioutil.WriteFile("config_unittest.yml", configString, 0644)
|
||||
}
|
||||
|
||||
// Writes a config that is empty
|
||||
func writeEmptyConfig() error {
|
||||
cleanUp()
|
||||
return ioutil.WriteFile("config.yml", []byte(""), 0644)
|
||||
return ioutil.WriteFile("config_unittest.yml", []byte(""), 0644)
|
||||
}
|
||||
|
||||
// Writes a config with invalid entries
|
||||
|
@ -196,9 +197,9 @@ func writeInvalidConfig() error {
|
|||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile("config.yml", configString, 0644)
|
||||
return ioutil.WriteFile("config_unittest.yml", configString, 0644)
|
||||
}
|
||||
|
||||
func cleanUp() error {
|
||||
return os.Remove("config.yml")
|
||||
return os.Remove("config_unittest.yml")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue