MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestConfig_MergeWithFile_ProfileBased

Function TestConfig_MergeWithFile_ProfileBased

internal/config/config_test.go:934–1004  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

932}
933
934func TestConfig_MergeWithFile_ProfileBased(t *testing.T) {
935 // Create a temporary directory for test files
936 tempDir := t.TempDir()
937
938 // Test merging with profile-based configuration
939 initialConfig := &Config{
940 Profiles: map[string]ProfileConfig{
941 "default": {
942 Addr: "https://initial.example.com:8006",
943 User: "initialuser",
944 SSHJumpHost: SSHJumpHost{
945 Addr: "initial-jump.example.com",
946 },
947 },
948 },
949 DefaultProfile: "default",
950 }
951
952 fileContent := `
953profiles:
954 default:
955 addr: "https://merged.example.com:8006"
956 password: "mergedpass"
957 ssh_jump_host:
958 addr: "jump.example.com"
959 user: "jumpuser"
960 port: 2222
961 secondary:
962 addr: "https://secondary.example.com:8006"
963 user: "secondaryuser"
964 password: "secondarypass"
965default_profile: "default"
966debug: true
967`
968
969 // Create temporary file
970 file, err := os.CreateTemp(tempDir, "config-*.yml")
971 require.NoError(t, err)
972 defer os.Remove(file.Name())
973
974 _, err = file.WriteString(fileContent)
975 require.NoError(t, err)
976 file.Close()
977
978 // Test merge
979 err = initialConfig.MergeWithFile(file.Name())
980 assert.NoError(t, err)
981
982 // Verify profiles were merged correctly
983 assert.Len(t, initialConfig.Profiles, 2)
984
985 // Check default profile
986 defaultProfile, exists := initialConfig.Profiles["default"]
987 assert.True(t, exists)
988 assert.Equal(t, "https://merged.example.com:8006", defaultProfile.Addr)
989 assert.Equal(t, "initialuser", defaultProfile.User) // Should keep initial value
990 assert.Equal(t, "mergedpass", defaultProfile.Password)
991 assert.Equal(t, "jump.example.com", defaultProfile.SSHJumpHost.Addr)

Callers

nothing calls this directly

Calls 3

MergeWithFileMethod · 0.95
NameMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected