Skip to content

Commit 3a6e0ec

Browse files
committed
Add an integration test for #155.
1 parent ded776b commit 3a6e0ec

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

internal/fs/local_modifications_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,44 @@ func (t *FileTest) AtimeAndCtime() {
21352135
ExpectThat(ctime, timeutil.TimeNear(createTime, delta))
21362136
}
21372137

2138+
func (t *FileTest) ContentTypes() {
2139+
testCases := map[string]string{
2140+
"foo.jpg": "image/jpeg",
2141+
"bar.txt": "text/plain; charset=utf-8",
2142+
"baz": "application/octet-stream",
2143+
}
2144+
2145+
runOne := func(name string, expected string) {
2146+
p := path.Join(t.mfs.Dir(), name)
2147+
2148+
// Create a file.
2149+
f, err := os.Create(p)
2150+
AssertEq(nil, err)
2151+
defer f.Close()
2152+
2153+
// Check the GCS content type.
2154+
o, err := t.bucket.StatObject(t.ctx, &gcs.StatObjectRequest{Name: name})
2155+
AssertEq(nil, err)
2156+
ExpectEq(expected, o.ContentType, "name: %q", name)
2157+
2158+
// Modify the file and cause a new generation to be written out.
2159+
_, err = f.Write([]byte("taco"))
2160+
AssertEq(nil, err)
2161+
2162+
err = f.Sync()
2163+
AssertEq(nil, err)
2164+
2165+
// The GCS content type should still be correct.
2166+
o, err = t.bucket.StatObject(t.ctx, &gcs.StatObjectRequest{Name: name})
2167+
AssertEq(nil, err)
2168+
ExpectEq(expected, o.ContentType, "name: %q", name)
2169+
}
2170+
2171+
for name, expected := range testCases {
2172+
runOne(name, expected)
2173+
}
2174+
}
2175+
21382176
////////////////////////////////////////////////////////////////////////
21392177
// Symlinks
21402178
////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)