MCPcopy Create free account
hub / github.com/bep/s3deploy / TestReduceInvalidationPaths

Function TestReduceInvalidationPaths

lib/cloudfront_test.go:21–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestReduceInvalidationPaths(t *testing.T) {
22 c := qt.New(t)
23
24 var client *cloudFrontClient
25
26 c.Assert(client.normalizeInvalidationPaths("root", 5, false, "/root/index.html"), qt.DeepEquals, []string{"/root/"})
27 c.Assert(client.normalizeInvalidationPaths("", 5, false, "/index.html"), qt.DeepEquals, []string{"/"})
28 c.Assert(client.normalizeInvalidationPaths("", 5, true, "/a", "/b"), qt.DeepEquals, []string{"/*"})
29 c.Assert(client.normalizeInvalidationPaths("root", 5, true, "/a", "/b"), qt.DeepEquals, []string{"/root/*"})
30 c.Assert(client.normalizeInvalidationPaths("root", 5, false, "/root/b/"), qt.DeepEquals, []string{"/root/b/"})
31
32 rootPlusMany := append([]string{"/index.html", "/styles.css"}, createFiles("css", false, 20)...)
33 normalized := client.normalizeInvalidationPaths("", 5, false, rootPlusMany...)
34 c.Assert(len(normalized), qt.DeepEquals, 3)
35 c.Assert(normalized, qt.DeepEquals, []string{"/", "/css/*", "/styles.css"})
36
37 rootPlusManyInDifferentFolders := append([]string{"/index.html", "/styles.css"}, createFiles("css", true, 20)...)
38 c.Assert(client.normalizeInvalidationPaths("", 5, false, rootPlusManyInDifferentFolders...), qt.DeepEquals, []string{"/*"})
39
40 rootPlusManyInDifferentFoldersNested := append([]string{"/index.html", "/styles.css"}, createFiles("blog", false, 10)...)
41 rootPlusManyInDifferentFoldersNested = append(rootPlusManyInDifferentFoldersNested, createFiles("blog/l1", false, 10)...)
42 rootPlusManyInDifferentFoldersNested = append(rootPlusManyInDifferentFoldersNested, createFiles("blog/l1/l2/l3/l5", false, 10)...)
43 rootPlusManyInDifferentFoldersNested = append(rootPlusManyInDifferentFoldersNested, createFiles("blog/l1/l3", false, 10)...)
44 rootPlusManyInDifferentFoldersNested = append(rootPlusManyInDifferentFoldersNested, createFiles("about/l1", true, 10)...)
45 rootPlusManyInDifferentFoldersNested = append(rootPlusManyInDifferentFoldersNested, createFiles("about/l1/l2/l3", false, 10)...)
46
47 // avoid situations where many changes in some HTML template triggers update in /images and similar
48 normalized = client.normalizeInvalidationPaths("", 5, false, rootPlusManyInDifferentFoldersNested...)
49 c.Assert(len(normalized), qt.Equals, 4)
50 c.Assert(normalized, qt.DeepEquals, []string{"/", "/about/*", "/blog/*", "/styles.css"})
51
52 changes := []string{"/hugoscss/categories/index.html", "/hugoscss/index.html", "/hugoscss/tags/index.html", "/hugoscss/post/index.html", "/hugoscss/post/hello-scss/index.html", "/hugoscss/styles/main.min.36816b22057425f8a5f66b73918446b0cd793c0c6125406c285948f507599d1e.css"}
53 normalized = client.normalizeInvalidationPaths("/hugoscss", 3, false, changes...)
54 c.Assert(normalized, qt.DeepEquals, []string{"/hugoscss/*"})
55
56 changes = []string{"/a/b1/a.css", "/a/b2/b.css"}
57 normalized = client.normalizeInvalidationPaths("/", 3, false, changes...)
58 c.Assert(normalized, qt.DeepEquals, []string{"/a/b1/a.css", "/a/b2/b.css"})
59
60 normalized = client.normalizeInvalidationPaths("/", 1, false, changes...)
61 c.Assert(normalized, qt.DeepEquals, []string{"/a/*"})
62
63 // Force
64 normalized = client.normalizeInvalidationPaths("", 5, true, rootPlusManyInDifferentFoldersNested...)
65 c.Assert(normalized, qt.DeepEquals, []string{"/*"})
66 normalized = client.normalizeInvalidationPaths("root", 5, true, rootPlusManyInDifferentFoldersNested...)
67 c.Assert(normalized, qt.DeepEquals, []string{"/root/*"})
68}
69
70func TestDetermineRootAndSubPath(t *testing.T) {
71 c := qt.New(t)

Callers

nothing calls this directly

Calls 2

createFilesFunction · 0.85

Tested by

no test coverage detected