mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-21 18:50:13 +00:00
test(agentcompat): configure connection count sampling
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
@@ -38,7 +38,7 @@ func (agent *Agent) prepareConfig(config AgentStartConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
agent.configPath = configPath
|
agent.configPath = configPath
|
||||||
content := fmt.Sprintf("server: %q\nclient_secret: %q\nuuid: %q\ndisable_auto_update: true\ndisable_command_execute: false\ndisable_nat: false\nreport_delay: 1\nip_report_period: 30\ntls: %t\ninsecure_tls: false\ndebug: %t\n", config.Endpoint, config.Secret, config.UUID, config.TLS, config.Debug)
|
content := fmt.Sprintf("server: %q\nclient_secret: %q\nuuid: %q\ndisable_auto_update: true\ndisable_command_execute: false\ndisable_nat: false\nreport_delay: 1\nip_report_period: 30\nskip_connection_count: %t\ntls: %t\ninsecure_tls: false\ndebug: %t\n", config.Endpoint, config.Secret, config.UUID, config.SkipConnectionCount, config.TLS, config.Debug)
|
||||||
if err := os.WriteFile(configPath, []byte(content), 0o600); err != nil {
|
if err := os.WriteFile(configPath, []byte(content), 0o600); err != nil {
|
||||||
return fmt.Errorf("write agent config: %w", err)
|
return fmt.Errorf("write agent config: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nezhahq/nezha/integration/agentcompat/internal/workspace"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAgent_PrepareConfigWritesSkipConnectionCount(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
config AgentStartConfig
|
||||||
|
expectedConfigLine []byte
|
||||||
|
unexpectedConfigLine []byte
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "writes enabled value when requested",
|
||||||
|
config: AgentStartConfig{SkipConnectionCount: true},
|
||||||
|
expectedConfigLine: []byte("skip_connection_count: true\n"),
|
||||||
|
unexpectedConfigLine: []byte("skip_connection_count: false\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "writes disabled value by default",
|
||||||
|
expectedConfigLine: []byte("skip_connection_count: false\n"),
|
||||||
|
unexpectedConfigLine: []byte("skip_connection_count: true\n"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
// Given
|
||||||
|
workspaceRoot, err := workspace.New(t.Context())
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Cleanup(func() { require.NoError(t, workspaceRoot.Close()) })
|
||||||
|
agent := &Agent{workspace: workspaceRoot}
|
||||||
|
|
||||||
|
// When
|
||||||
|
err = agent.prepareConfig(testCase.config)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
require.NoError(t, err)
|
||||||
|
configBytes, err := os.ReadFile(agent.ConfigPath())
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, bytes.Contains(configBytes, testCase.expectedConfigLine))
|
||||||
|
require.False(t, bytes.Contains(configBytes, testCase.unexpectedConfigLine))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user