45 lines
946 B
Go
45 lines
946 B
Go
|
|
package config_test
|
||
|
|
|
||
|
|
import (
|
||
|
|
"path/filepath"
|
||
|
|
"runtime"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"gateway/internal/config"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/conf"
|
||
|
|
)
|
||
|
|
|
||
|
|
func repoRoot(t *testing.T) string {
|
||
|
|
t.Helper()
|
||
|
|
_, file, _, _ := runtime.Caller(0)
|
||
|
|
return filepath.Clean(filepath.Join(filepath.Dir(file), "..", ".."))
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestLoadGatewayYAML_default(t *testing.T) {
|
||
|
|
t.Parallel()
|
||
|
|
var c config.Config
|
||
|
|
path := filepath.Join(repoRoot(t), "etc", "gateway.yaml")
|
||
|
|
if err := conf.Load(path, &c); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if c.Port != 8888 {
|
||
|
|
t.Fatalf("Port = %d", c.Port)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestLoadGatewayYAML_dev(t *testing.T) {
|
||
|
|
t.Parallel()
|
||
|
|
var c config.Config
|
||
|
|
path := filepath.Join(repoRoot(t), "etc", "gateway.dev.yaml")
|
||
|
|
if err := conf.Load(path, &c); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if c.Mongo.Host == "" {
|
||
|
|
t.Fatal("Mongo.Host should be set in gateway.dev.yaml")
|
||
|
|
}
|
||
|
|
if c.Redis.Host == "" {
|
||
|
|
t.Fatal("Redis.Host should be set in gateway.dev.yaml")
|
||
|
|
}
|
||
|
|
}
|