mirror of
https://github.com/dragonheim/gagent.git
synced 2025-05-24 13:26:48 -07:00
feat: Adding very preliminar and broken test harness.
This commit is contained in:
parent
ac8c225752
commit
7f9a5777bd
14 changed files with 678 additions and 10 deletions
|
@ -300,7 +300,8 @@ func init() {
|
|||
if config.MonitorPort != 0 {
|
||||
go func() {
|
||||
log.Printf("[INFO] Starting Prometheus metrics exporter on port %d\n", config.MonitorPort)
|
||||
log.Fatal(http.ListenAndServe(string(config.ListenAddr)+":"+strconv.Itoa(config.MonitorPort), nil))
|
||||
err := http.ListenAndServe(string(config.ListenAddr)+":"+strconv.Itoa(config.MonitorPort), nil)
|
||||
log.Printf("[ERROR] Prometheus metrics exporter returned: %s\n", err)
|
||||
}()
|
||||
}
|
||||
autorestart.WatchFilename = config.File
|
||||
|
|
71
cmd/gagent/main_test.go
Normal file
71
cmd/gagent/main_test.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
package main_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
main "github.com/dragonheim/gagent/cmd/gagent"
|
||||
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
||||
)
|
||||
|
||||
// This function will create a temporary config file for testing purposes
|
||||
func createTestConfigFile() (string, error) {
|
||||
tmpfile, err := ioutil.TempFile("", "test_config_*.hcl")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
content := []byte(`mode = "setup"
|
||||
listen_addr = "0.0.0.0"
|
||||
monitor_port = 8888
|
||||
client_port = 35572
|
||||
router_port = 35570
|
||||
worker_port = 35571
|
||||
`)
|
||||
if _, err := tmpfile.Write(content); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := tmpfile.Close(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return tmpfile.Name(), nil
|
||||
}
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
t.Run("Test setup mode with temp config file", func(t *testing.T) {
|
||||
tmpConfig, err := createTestConfigFile()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp config file: %v", err)
|
||||
}
|
||||
defer os.Remove(tmpConfig)
|
||||
|
||||
config := gstructs.GagentConfig{
|
||||
File: tmpConfig,
|
||||
Mode: "setup",
|
||||
}
|
||||
|
||||
// Run the main function with the temporary config
|
||||
main.Run(config)
|
||||
|
||||
// Check if the config has been set up correctly
|
||||
expectedConfig := gstructs.GagentConfig{
|
||||
Mode: "setup",
|
||||
ListenAddr: "0.0.0.0",
|
||||
MonitorPort: 8888,
|
||||
ClientPort: 35572,
|
||||
RouterPort: 35570,
|
||||
WorkerPort: 35571,
|
||||
}
|
||||
|
||||
if config.Mode != expectedConfig.Mode ||
|
||||
config.ListenAddr != expectedConfig.ListenAddr ||
|
||||
config.MonitorPort != expectedConfig.MonitorPort ||
|
||||
config.ClientPort != expectedConfig.ClientPort ||
|
||||
config.RouterPort != expectedConfig.RouterPort ||
|
||||
config.WorkerPort != expectedConfig.WorkerPort {
|
||||
t.Fatalf("Expected config %+v, got %+v", expectedConfig, config)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue