Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite8a9358

Browse files
committed
chore: Refactor site to improve testing (#2014)
It was difficult to develop this package due to theembed build tag being mandatory on the tests. The logicto test doesn't require any embedded files.
1 parentf6e6e71 commite8a9358

File tree

6 files changed

+40
-40
lines changed

6 files changed

+40
-40
lines changed

‎coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func New(options *Options) *API {
334334
r.Get("/state",api.workspaceBuildState)
335335
})
336336
})
337-
r.NotFound(site.DefaultHandler().ServeHTTP)
337+
r.NotFound(site.Handler(site.FS()).ServeHTTP)
338338

339339
returnapi
340340
}

‎site/embed_slim.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎site/embed.gorenamed to‎site/site.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
//go:build embed
2-
// +build embed
3-
41
package site
52

63
import (
74
"bytes"
8-
"embed"
95
"fmt"
106
"io"
117
"io/fs"
@@ -21,26 +17,6 @@ import (
2117
"golang.org/x/xerrors"
2218
)
2319

24-
// The `embed` package ignores recursively including directories
25-
// that prefix with `_`. Wildcarding nested is janky, but seems to
26-
// work quite well for edge-cases.
27-
//go:embed out
28-
//go:embed out/bin/*
29-
varsite embed.FS
30-
31-
funcDefaultHandler() http.Handler {
32-
// the out directory is where webpack builds are created. It is in the same
33-
// directory as this file (package site).
34-
siteFS,err:=fs.Sub(site,"out")
35-
36-
iferr!=nil {
37-
// This can't happen... Go would throw a compilation error.
38-
panic(err)
39-
}
40-
41-
returnHandler(siteFS)
42-
}
43-
4420
// Handler returns an HTTP handler for serving the static site.
4521
funcHandler(fileSystem fs.FS) http.Handler {
4622
// html files are handled by a text/template. Non-html files

‎site/site_embed.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//go:build embed
2+
// +build embed
3+
4+
package site
5+
6+
import (
7+
"embed"
8+
"io/fs"
9+
)
10+
11+
//go:embed out
12+
//go:embed out/bin/*
13+
varsite embed.FS
14+
15+
funcFS() fs.FS {
16+
// the out directory is where webpack builds are created. It is in the same
17+
// directory as this file (package site).
18+
out,err:=fs.Sub(site,"out")
19+
iferr!=nil {
20+
// This can't happen... Go would throw a compilation error.
21+
panic(err)
22+
}
23+
returnout
24+
}

‎site/site_slim.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build !embed
2+
// +build !embed
3+
4+
package site
5+
6+
import (
7+
"embed"
8+
"io/fs"
9+
)
10+
11+
varslim embed.FS
12+
13+
funcFS() fs.FS {
14+
returnslim
15+
}

‎site/embed_test.gorenamed to‎site/site_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build embed
2-
// +build embed
3-
41
package site_test
52

63
import (

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp