MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / TestHTTPSIndexDisablesCaching

Function TestHTTPSIndexDisablesCaching

internal/web/admin_https_test.go:76–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestHTTPSIndexDisablesCaching(t *testing.T) {
77 mudlog.SetupLogger(nil, "", "", false)
78
79 wd, err := os.Getwd()
80 if err != nil {
81 t.Fatalf("os.Getwd() error = %v", err)
82 }
83 repoRoot := filepath.Clean(filepath.Join(wd, "..", ".."))
84 if err := os.Chdir(repoRoot); err != nil {
85 t.Fatalf("os.Chdir() error = %v", err)
86 }
87 t.Cleanup(func() {
88 if err := os.Chdir(wd); err != nil {
89 t.Fatalf("os.Chdir() cleanup error = %v", err)
90 }
91 })
92
93 adminDir := t.TempDir()
94 for name, contents := range map[string]string{
95 "_header.html": "header",
96 "_nav.html": "",
97 "https.html": "nav={{len .NAV}}|{{.httpsStatus}}",
98 "_footer.html": "footer",
99 } {
100 if err := os.WriteFile(filepath.Join(adminDir, name), []byte(contents), 0o600); err != nil {
101 t.Fatalf("os.WriteFile() error = %v", err)
102 }
103 }
104
105 overridePath := filepath.Join(t.TempDir(), "config-overrides.yaml")
106 overrideConfig := "FilePaths:\n AdminHtml: \"" + strings.ReplaceAll(adminDir, "\\", "\\\\") + "\"\n"
107 if err := os.WriteFile(overridePath, []byte(overrideConfig), 0o600); err != nil {
108 t.Fatalf("os.WriteFile() error = %v", err)
109 }
110
111 oldConfigPath, hadConfigPath := os.LookupEnv("CONFIG_PATH")
112 if err := os.Setenv("CONFIG_PATH", overridePath); err != nil {
113 t.Fatalf("os.Setenv() error = %v", err)
114 }
115 if err := configs.ReloadConfig(); err != nil {
116 t.Fatalf("configs.ReloadConfig() error = %v", err)
117 }
118 t.Cleanup(func() {
119 if hadConfigPath {
120 _ = os.Setenv("CONFIG_PATH", oldConfigPath)
121 } else {
122 _ = os.Unsetenv("CONFIG_PATH")
123 }
124 if err := configs.ReloadConfig(); err != nil {
125 t.Fatalf("configs.ReloadConfig() cleanup error = %v", err)
126 }
127 })
128
129 req := httptest.NewRequest(http.MethodGet, "/admin/https/", nil)
130 rec := httptest.NewRecorder()
131
132 httpsIndex(rec, req)
133

Callers

nothing calls this directly

Calls 5

SetupLoggerFunction · 0.92
ReloadConfigFunction · 0.92
httpsIndexFunction · 0.85
StringMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected