MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / TestLoadAuthTokenFromFile

Function TestLoadAuthTokenFromFile

apps/server/internal/config/config_test.go:10–27  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestLoadAuthTokenFromFile(t *testing.T) {
11 tokenFile := filepath.Join(t.TempDir(), "token")
12 const want = "from-file-token-xxxxxx"
13 if err := os.WriteFile(tokenFile, []byte(" "+want+"\n"), 0o600); err != nil {
14 t.Fatal(err)
15 }
16 t.Setenv("ZENNOTES_AUTH_TOKEN", "")
17 t.Setenv("ZENNOTES_AUTH_TOKEN_FILE", tokenFile)
18 t.Setenv("ZENNOTES_CONFIG_PATH", filepath.Join(t.TempDir(), "missing.json"))
19
20 cfg := Load()
21 if cfg.AuthToken != want {
22 t.Fatalf("AuthToken = %q, want %q (whitespace must be trimmed)", cfg.AuthToken, want)
23 }
24 if cfg.AuthTokenSource != AuthTokenSourceFile {
25 t.Fatalf("AuthTokenSource = %q, want %q", cfg.AuthTokenSource, AuthTokenSourceFile)
26 }
27}
28
29func TestEnvAuthTokenWinsOverFile(t *testing.T) {
30 tokenFile := filepath.Join(t.TempDir(), "token")

Callers

nothing calls this directly

Calls 1

LoadFunction · 0.85

Tested by

no test coverage detected