(t *testing.T)
| 119 | } |
| 120 | |
| 121 | func TestAssetsDir(t *testing.T) { |
| 122 | t.Parallel() |
| 123 | |
| 124 | // For any given request to $FILE, we should return the first found of |
| 125 | // - assetsdir/$THEME/$FILE |
| 126 | // - compiled in asset $THEME/$FILE |
| 127 | // - assetsdir/default/$FILE |
| 128 | // - compiled in asset default/$FILE |
| 129 | |
| 130 | // The asset map contains compressed assets, so create a couple of gzip compressed assets here. |
| 131 | buf := new(bytes.Buffer) |
| 132 | gw := gzip.NewWriter(buf) |
| 133 | gw.Write([]byte("default")) |
| 134 | gw.Close() |
| 135 | def := assets.Asset{ |
| 136 | Content: buf.String(), |
| 137 | Gzipped: true, |
| 138 | } |
| 139 | |
| 140 | buf = new(bytes.Buffer) |
| 141 | gw = gzip.NewWriter(buf) |
| 142 | gw.Write([]byte("foo")) |
| 143 | gw.Close() |
| 144 | foo := assets.Asset{ |
| 145 | Content: buf.String(), |
| 146 | Gzipped: true, |
| 147 | } |
| 148 | |
| 149 | e := &staticsServer{ |
| 150 | theme: "foo", |
| 151 | assetDir: "testdata", |
| 152 | assets: map[string]assets.Asset{ |
| 153 | "foo/a": foo, // overridden in foo/a |
| 154 | "foo/b": foo, |
| 155 | "default/a": def, // overridden in default/a (but foo/a takes precedence) |
| 156 | "default/b": def, // overridden in default/b (but foo/b takes precedence) |
| 157 | "default/c": def, |
| 158 | }, |
| 159 | } |
| 160 | |
| 161 | s := httptest.NewServer(e) |
| 162 | defer s.Close() |
| 163 | |
| 164 | // assetsdir/foo/a exists, overrides compiled in |
| 165 | expectURLToContain(t, s.URL+"/a", "overridden-foo") |
| 166 | |
| 167 | // foo/b is compiled in, default/b is overridden, return compiled in |
| 168 | expectURLToContain(t, s.URL+"/b", "foo") |
| 169 | |
| 170 | // only exists as compiled in default/c so use that |
| 171 | expectURLToContain(t, s.URL+"/c", "default") |
| 172 | |
| 173 | // only exists as overridden default/d so use that |
| 174 | expectURLToContain(t, s.URL+"/d", "overridden-default") |
| 175 | } |
| 176 | |
| 177 | func expectURLToContain(t *testing.T, url, exp string) { |
| 178 | res, err := http.Get(url) |
nothing calls this directly
no test coverage detected