package main import ( "net/http" "net/http/httptest" "strings" "testing" ) func TestServeLegalDocument(t *testing.T) { tests := []struct { path string title string }{ {path: "/legal/user-terms", title: "讯工捷使软件服务协议"}, {path: "/legal/privacy-policy", title: "讯工捷使隐私政策"}, } for _, tc := range tests { t.Run(tc.path, func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, tc.path, nil) rec := httptest.NewRecorder() serveLegalDocument(rec, req) if rec.Code != http.StatusOK { t.Fatalf("status: got %d body=%s", rec.Code, rec.Body.String()) } if got := rec.Header().Get("Content-Type"); got != "text/html; charset=utf-8" { t.Fatalf("content type: got %q", got) } if rec.Header().Get("ETag") == "" { t.Fatal("missing ETag") } if !strings.Contains(rec.Body.String(), "