@@ -36,13 +36,17 @@ func TestOverrideVSCodeConfigs(t *testing.T) {
36
36
require .Equal (t , false , mapping ["github.gitAuthentication" ])
37
37
}
38
38
})
39
- t .Run ("Append " , func (t * testing.T ) {
39
+ t .Run ("MergeWithExistingSettings " , func (t * testing.T ) {
40
40
t .Parallel ()
41
41
fs := afero .NewMemMapFs ()
42
- mapping := map [string ]interface {}{
43
- "hotdogs" : "something" ,
42
+ // Create existing settings with user preferences
43
+ existingSettings := map [string ]interface {}{
44
+ "workbench.colorTheme" : "Dracula" ,
45
+ "editor.fontSize" : 14 ,
46
+ "editor.tabSize" : 2 ,
47
+ "files.autoSave" : "onWindowChange" ,
44
48
}
45
- data , err := json .Marshal ( mapping )
49
+ data , err := json .MarshalIndent ( existingSettings , "" , " \t " )
46
50
require .NoError (t , err )
47
51
for _ , configPath := range configPaths {
48
52
err = afero .WriteFile (fs , configPath , data , 0o600 )
@@ -56,9 +60,95 @@ func TestOverrideVSCodeConfigs(t *testing.T) {
56
60
mapping := map [string ]interface {}{}
57
61
err = json .Unmarshal (data , & mapping )
58
62
require .NoError (t , err )
63
+ // Verify Coder settings are applied
64
+ require .Equal (t , false , mapping ["git.useIntegratedAskPass" ])
65
+ require .Equal (t , false , mapping ["github.gitAuthentication" ])
66
+ // Verify user settings are preserved
67
+ require .Equal (t , "Dracula" , mapping ["workbench.colorTheme" ])
68
+ require .Equal (t , float64 (14 ), mapping ["editor.fontSize" ])
69
+ require .Equal (t , float64 (2 ), mapping ["editor.tabSize" ])
70
+ require .Equal (t , "onWindowChange" , mapping ["files.autoSave" ])
71
+ // Verify no duplication - should have exactly 6 settings
72
+ require .Len (t , mapping , 6 )
73
+ }
74
+ })
75
+
76
+ t .Run ("MergeWithExistingCoderSettings" , func (t * testing.T ) {
77
+ t .Parallel ()
78
+ fs := afero .NewMemMapFs ()
79
+ // Create existing settings that include Coder-specific settings with different values
80
+ existingSettings := map [string ]interface {}{
81
+ "workbench.colorTheme" : "Dark+" ,
82
+ "git.useIntegratedAskPass" : true , // This should be overridden to false
83
+ "github.gitAuthentication" : true , // This should be overridden to false
84
+ "editor.wordWrap" : "on" ,
85
+ "terminal.integrated.shell.linux" : "/bin/bash" ,
86
+ }
87
+ data , err := json .MarshalIndent (existingSettings , "" , "\t " )
88
+ require .NoError (t , err )
89
+ for _ , configPath := range configPaths {
90
+ err = afero .WriteFile (fs , configPath , data , 0o600 )
91
+ require .NoError (t , err )
92
+ }
93
+ err = gitauth .OverrideVSCodeConfigs (fs )
94
+ require .NoError (t , err )
95
+ for _ , configPath := range configPaths {
96
+ data , err := afero .ReadFile (fs , configPath )
97
+ require .NoError (t , err )
98
+ mapping := map [string ]interface {}{}
99
+ err = json .Unmarshal (data , & mapping )
100
+ require .NoError (t , err )
101
+ // Verify Coder settings override existing values
102
+ require .Equal (t , false , mapping ["git.useIntegratedAskPass" ])
103
+ require .Equal (t , false , mapping ["github.gitAuthentication" ])
104
+ // Verify user settings are preserved
105
+ require .Equal (t , "Dark+" , mapping ["workbench.colorTheme" ])
106
+ require .Equal (t , "on" , mapping ["editor.wordWrap" ])
107
+ require .Equal (t , "/bin/bash" , mapping ["terminal.integrated.shell.linux" ])
108
+ // Verify no duplication - should have exactly 5 settings
109
+ require .Len (t , mapping , 5 )
110
+ }
111
+ })
112
+
113
+ t .Run ("ValidJSONOutput" , func (t * testing.T ) {
114
+ t .Parallel ()
115
+ fs := afero .NewMemMapFs ()
116
+ // Test with complex existing settings to ensure valid JSON output
117
+ existingSettings := map [string ]interface {}{
118
+ "workbench.colorCustomizations" : map [string ]interface {}{
119
+ "editor.background" : "#1e1e1e" ,
120
+ "sideBar.background" : "#252526" ,
121
+ },
122
+ "extensions.recommendations" : []string {"ms-python.python" , "golang.go" },
123
+ "git.useIntegratedAskPass" : true ,
124
+ "editor.rulers" : []int {80 , 120 },
125
+ }
126
+ data , err := json .MarshalIndent (existingSettings , "" , "\t " )
127
+ require .NoError (t , err )
128
+ for _ , configPath := range configPaths {
129
+ err = afero .WriteFile (fs , configPath , data , 0o600 )
130
+ require .NoError (t , err )
131
+ }
132
+ err = gitauth .OverrideVSCodeConfigs (fs )
133
+ require .NoError (t , err )
134
+ for _ , configPath := range configPaths {
135
+ data , err := afero .ReadFile (fs , configPath )
136
+ require .NoError (t , err )
137
+ // Verify the output is valid JSON
138
+ mapping := map [string ]interface {}{}
139
+ err = json .Unmarshal (data , & mapping )
140
+ require .NoError (t , err , "Output should be valid JSON" )
141
+ // Verify complex structures are preserved
142
+ colorCustomizations , ok := mapping ["workbench.colorCustomizations" ].(map [string ]interface {})
143
+ require .True (t , ok , "Complex objects should be preserved" )
144
+ require .Equal (t , "#1e1e1e" , colorCustomizations ["editor.background" ])
145
+ // Verify arrays are preserved
146
+ recommendations , ok := mapping ["extensions.recommendations" ].([]interface {})
147
+ require .True (t , ok , "Arrays should be preserved" )
148
+ require .Len (t , recommendations , 2 )
149
+ // Verify Coder settings are applied
59
150
require .Equal (t , false , mapping ["git.useIntegratedAskPass" ])
60
151
require .Equal (t , false , mapping ["github.gitAuthentication" ])
61
- require .Equal (t , "something" , mapping ["hotdogs" ])
62
152
}
63
153
})
64
154
}
0 commit comments