@@ -89,13 +89,13 @@ func TestFile_Marshal(t *testing.T) {
89
89
if err != nil {
90
90
t .Error (err )
91
91
}
92
+ f .clock = clock .NewMock ()
92
93
93
94
err = f .Load (context .Background ())
94
95
if err != nil {
95
96
t .Error (errors .Wrap (err , "failed to load valid hosts file" ))
96
97
}
97
98
98
- f .clock = clock .NewMock ()
99
99
b , err := f .Marshal (context .Background ())
100
100
if err != nil {
101
101
t .Error (errors .Wrap (err , "failed to marshal hosts file" ))
@@ -111,13 +111,13 @@ func TestFile_Marshal(t *testing.T) {
111
111
if err != nil {
112
112
t .Error (err )
113
113
}
114
+ f .clock = clock .NewMock ()
114
115
115
116
err = f .Load (context .Background ())
116
117
if err != nil {
117
118
t .Error (errors .Wrap (err , "failed to load valid hosts file" ))
118
119
}
119
120
120
- f .clock = clock .NewMock ()
121
121
b , err = f .Marshal (context .Background ())
122
122
if err != nil {
123
123
t .Error (errors .Wrap (err , "failed to marshal hosts file" ))
@@ -131,6 +131,34 @@ func TestFile_Marshal(t *testing.T) {
131
131
if ! reflect .DeepEqual (expected , b ) {
132
132
t .Error ("expected: " , cmp .Diff (expected , b ))
133
133
}
134
+
135
+ // modify a hosts file outside of our library, ensure the changes
136
+ // are kept when Marshal'd
137
+ filePath = "./testdata/load/hosts-with-block.hosts"
138
+ f , err = New (filePath , "" )
139
+ if err != nil {
140
+ t .Error (err )
141
+ }
142
+ f .clock = clock .NewMock ()
143
+
144
+ err = f .Load (context .Background ())
145
+ if err != nil {
146
+ t .Error (errors .Wrap (err , "failed to load valid hosts file" ))
147
+ }
148
+
149
+ // append a new entry
150
+ f .contents = append ([]byte (
151
+ "127.0.0.1 helloworld.name.io\n " ,
152
+ ), f .contents ... )
153
+
154
+ b , err = f .Marshal (context .Background ())
155
+ if err != nil {
156
+ t .Error (errors .Wrap (err , "failed to marshal hosts file" ))
157
+ }
158
+
159
+ if ! reflect .DeepEqual (b , f .contents ) {
160
+ t .Error ("expected: " , cmp .Diff (b , f .contents ))
161
+ }
134
162
}
135
163
136
164
// Ensure that we don't corrupt hosts files that have data inside of
0 commit comments