routes_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. package server
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/binary"
  6. "encoding/json"
  7. "fmt"
  8. "io"
  9. "io/fs"
  10. "math"
  11. "math/rand/v2"
  12. "net"
  13. "net/http"
  14. "net/http/httptest"
  15. "os"
  16. "path/filepath"
  17. "sort"
  18. "strings"
  19. "testing"
  20. "unicode"
  21. "github.com/ollama/ollama/api"
  22. "github.com/ollama/ollama/llm"
  23. "github.com/ollama/ollama/openai"
  24. "github.com/ollama/ollama/parser"
  25. "github.com/ollama/ollama/types/model"
  26. "github.com/ollama/ollama/version"
  27. )
  28. func createTestFile(t *testing.T, name string) string {
  29. t.Helper()
  30. f, err := os.CreateTemp(t.TempDir(), name)
  31. if err != nil {
  32. t.Fatalf("failed to create temp file: %v", err)
  33. }
  34. defer f.Close()
  35. err = binary.Write(f, binary.LittleEndian, []byte("GGUF"))
  36. if err != nil {
  37. t.Fatalf("failed to write to file: %v", err)
  38. }
  39. err = binary.Write(f, binary.LittleEndian, uint32(3))
  40. if err != nil {
  41. t.Fatalf("failed to write to file: %v", err)
  42. }
  43. err = binary.Write(f, binary.LittleEndian, uint64(0))
  44. if err != nil {
  45. t.Fatalf("failed to write to file: %v", err)
  46. }
  47. err = binary.Write(f, binary.LittleEndian, uint64(0))
  48. if err != nil {
  49. t.Fatalf("failed to write to file: %v", err)
  50. }
  51. return f.Name()
  52. }
  53. // equalStringSlices checks if two slices of strings are equal.
  54. func equalStringSlices(a, b []string) bool {
  55. if len(a) != len(b) {
  56. return false
  57. }
  58. for i := range a {
  59. if a[i] != b[i] {
  60. return false
  61. }
  62. }
  63. return true
  64. }
  65. func Test_Routes(t *testing.T) {
  66. type testCase struct {
  67. Name string
  68. Method string
  69. Path string
  70. Setup func(t *testing.T, req *http.Request)
  71. Expected func(t *testing.T, resp *http.Response)
  72. }
  73. createTestModel := func(t *testing.T, name string) {
  74. t.Helper()
  75. fname := createTestFile(t, "ollama-model")
  76. r := strings.NewReader(fmt.Sprintf("FROM %s\nPARAMETER seed 42\nPARAMETER top_p 0.9\nPARAMETER stop foo\nPARAMETER stop bar", fname))
  77. modelfile, err := parser.ParseFile(r)
  78. if err != nil {
  79. t.Fatalf("failed to parse file: %v", err)
  80. }
  81. fn := func(resp api.ProgressResponse) {
  82. t.Logf("Status: %s", resp.Status)
  83. }
  84. err = CreateModel(context.TODO(), model.ParseName(name), "", "", modelfile, fn)
  85. if err != nil {
  86. t.Fatalf("failed to create model: %v", err)
  87. }
  88. }
  89. testCases := []testCase{
  90. {
  91. Name: "Tags Handler (no tags)",
  92. Method: http.MethodGet,
  93. Path: "/api/tags",
  94. Expected: func(t *testing.T, resp *http.Response) {
  95. contentType := resp.Header.Get("Content-Type")
  96. if contentType != "application/json; charset=utf-8" {
  97. t.Errorf("expected content type application/json; charset=utf-8, got %s", contentType)
  98. }
  99. body, err := io.ReadAll(resp.Body)
  100. if err != nil {
  101. t.Fatalf("failed to read response body: %v", err)
  102. }
  103. var modelList api.ListResponse
  104. err = json.Unmarshal(body, &modelList)
  105. if err != nil {
  106. t.Fatalf("failed to unmarshal response body: %v", err)
  107. }
  108. if modelList.Models == nil || len(modelList.Models) != 0 {
  109. t.Errorf("expected empty model list, got %v", modelList.Models)
  110. }
  111. },
  112. },
  113. {
  114. Name: "openai empty list",
  115. Method: http.MethodGet,
  116. Path: "/v1/models",
  117. Expected: func(t *testing.T, resp *http.Response) {
  118. contentType := resp.Header.Get("Content-Type")
  119. if contentType != "application/json" {
  120. t.Errorf("expected content type application/json, got %s", contentType)
  121. }
  122. body, err := io.ReadAll(resp.Body)
  123. if err != nil {
  124. t.Fatalf("failed to read response body: %v", err)
  125. }
  126. var modelList openai.ListCompletion
  127. err = json.Unmarshal(body, &modelList)
  128. if err != nil {
  129. t.Fatalf("failed to unmarshal response body: %v", err)
  130. }
  131. if modelList.Object != "list" || len(modelList.Data) != 0 {
  132. t.Errorf("expected empty model list, got %v", modelList.Data)
  133. }
  134. },
  135. },
  136. {
  137. Name: "Tags Handler (yes tags)",
  138. Method: http.MethodGet,
  139. Path: "/api/tags",
  140. Setup: func(t *testing.T, req *http.Request) {
  141. createTestModel(t, "test-model")
  142. },
  143. Expected: func(t *testing.T, resp *http.Response) {
  144. contentType := resp.Header.Get("Content-Type")
  145. if contentType != "application/json; charset=utf-8" {
  146. t.Errorf("expected content type application/json; charset=utf-8, got %s", contentType)
  147. }
  148. body, err := io.ReadAll(resp.Body)
  149. if err != nil {
  150. t.Fatalf("failed to read response body: %v", err)
  151. }
  152. if strings.Contains(string(body), "expires_at") {
  153. t.Errorf("response body should not contain 'expires_at'")
  154. }
  155. var modelList api.ListResponse
  156. err = json.Unmarshal(body, &modelList)
  157. if err != nil {
  158. t.Fatalf("failed to unmarshal response body: %v", err)
  159. }
  160. if len(modelList.Models) != 1 || modelList.Models[0].Name != "test-model:latest" {
  161. t.Errorf("expected model 'test-model:latest', got %v", modelList.Models)
  162. }
  163. },
  164. },
  165. {
  166. Name: "Delete Model Handler",
  167. Method: http.MethodDelete,
  168. Path: "/api/delete",
  169. Setup: func(t *testing.T, req *http.Request) {
  170. createTestModel(t, "model-to-delete")
  171. deleteReq := api.DeleteRequest{
  172. Name: "model-to-delete",
  173. }
  174. jsonData, err := json.Marshal(deleteReq)
  175. if err != nil {
  176. t.Fatalf("failed to marshal delete request: %v", err)
  177. }
  178. req.Body = io.NopCloser(bytes.NewReader(jsonData))
  179. },
  180. Expected: func(t *testing.T, resp *http.Response) {
  181. if resp.StatusCode != http.StatusOK {
  182. t.Errorf("expected status code 200, got %d", resp.StatusCode)
  183. }
  184. // Verify the model was deleted
  185. _, err := GetModel("model-to-delete")
  186. if err == nil || !os.IsNotExist(err) {
  187. t.Errorf("expected model to be deleted, got error %v", err)
  188. }
  189. },
  190. },
  191. {
  192. Name: "Delete Non-existent Model",
  193. Method: http.MethodDelete,
  194. Path: "/api/delete",
  195. Setup: func(t *testing.T, req *http.Request) {
  196. deleteReq := api.DeleteRequest{
  197. Name: "non-existent-model",
  198. }
  199. jsonData, err := json.Marshal(deleteReq)
  200. if err != nil {
  201. t.Fatalf("failed to marshal delete request: %v", err)
  202. }
  203. req.Body = io.NopCloser(bytes.NewReader(jsonData))
  204. },
  205. Expected: func(t *testing.T, resp *http.Response) {
  206. if resp.StatusCode != http.StatusNotFound {
  207. t.Errorf("expected status code 404, got %d", resp.StatusCode)
  208. }
  209. body, err := io.ReadAll(resp.Body)
  210. if err != nil {
  211. t.Fatalf("failed to read response body: %v", err)
  212. }
  213. var errorResp map[string]string
  214. err = json.Unmarshal(body, &errorResp)
  215. if err != nil {
  216. t.Fatalf("failed to unmarshal response body: %v", err)
  217. }
  218. if !strings.Contains(errorResp["error"], "not found") {
  219. t.Errorf("expected error message to contain 'not found', got %s", errorResp["error"])
  220. }
  221. },
  222. },
  223. {
  224. Name: "openai list models with tags",
  225. Method: http.MethodGet,
  226. Path: "/v1/models",
  227. Expected: func(t *testing.T, resp *http.Response) {
  228. contentType := resp.Header.Get("Content-Type")
  229. if contentType != "application/json" {
  230. t.Errorf("expected content type application/json, got %s", contentType)
  231. }
  232. body, err := io.ReadAll(resp.Body)
  233. if err != nil {
  234. t.Fatalf("failed to read response body: %v", err)
  235. }
  236. var modelList openai.ListCompletion
  237. err = json.Unmarshal(body, &modelList)
  238. if err != nil {
  239. t.Fatalf("failed to unmarshal response body: %v", err)
  240. }
  241. if len(modelList.Data) != 1 || modelList.Data[0].Id != "test-model:latest" || modelList.Data[0].OwnedBy != "library" {
  242. t.Errorf("expected model 'test-model:latest' owned by 'library', got %v", modelList.Data)
  243. }
  244. },
  245. },
  246. {
  247. Name: "Create Model Handler",
  248. Method: http.MethodPost,
  249. Path: "/api/create",
  250. Setup: func(t *testing.T, req *http.Request) {
  251. fname := createTestFile(t, "ollama-model")
  252. stream := false
  253. createReq := api.CreateRequest{
  254. Name: "t-bone",
  255. Modelfile: fmt.Sprintf("FROM %s", fname),
  256. Stream: &stream,
  257. }
  258. jsonData, err := json.Marshal(createReq)
  259. if err != nil {
  260. t.Fatalf("failed to marshal create request: %v", err)
  261. }
  262. req.Body = io.NopCloser(bytes.NewReader(jsonData))
  263. },
  264. Expected: func(t *testing.T, resp *http.Response) {
  265. contentType := resp.Header.Get("Content-Type")
  266. if contentType != "application/json" {
  267. t.Errorf("expected content type application/json, got %s", contentType)
  268. }
  269. _, err := io.ReadAll(resp.Body)
  270. if err != nil {
  271. t.Fatalf("failed to read response body: %v", err)
  272. }
  273. if resp.StatusCode != http.StatusOK { // Updated line
  274. t.Errorf("expected status code 200, got %d", resp.StatusCode)
  275. }
  276. model, err := GetModel("t-bone")
  277. if err != nil {
  278. t.Fatalf("failed to get model: %v", err)
  279. }
  280. if model.ShortName != "t-bone:latest" {
  281. t.Errorf("expected model name 't-bone:latest', got %s", model.ShortName)
  282. }
  283. },
  284. },
  285. {
  286. Name: "Copy Model Handler",
  287. Method: http.MethodPost,
  288. Path: "/api/copy",
  289. Setup: func(t *testing.T, req *http.Request) {
  290. createTestModel(t, "hamshank")
  291. copyReq := api.CopyRequest{
  292. Source: "hamshank",
  293. Destination: "beefsteak",
  294. }
  295. jsonData, err := json.Marshal(copyReq)
  296. if err != nil {
  297. t.Fatalf("failed to marshal copy request: %v", err)
  298. }
  299. req.Body = io.NopCloser(bytes.NewReader(jsonData))
  300. },
  301. Expected: func(t *testing.T, resp *http.Response) {
  302. model, err := GetModel("beefsteak")
  303. if err != nil {
  304. t.Fatalf("failed to get model: %v", err)
  305. }
  306. if model.ShortName != "beefsteak:latest" {
  307. t.Errorf("expected model name 'beefsteak:latest', got %s", model.ShortName)
  308. }
  309. },
  310. },
  311. {
  312. Name: "Show Model Handler",
  313. Method: http.MethodPost,
  314. Path: "/api/show",
  315. Setup: func(t *testing.T, req *http.Request) {
  316. createTestModel(t, "show-model")
  317. showReq := api.ShowRequest{Model: "show-model"}
  318. jsonData, err := json.Marshal(showReq)
  319. if err != nil {
  320. t.Fatalf("failed to marshal show request: %v", err)
  321. }
  322. req.Body = io.NopCloser(bytes.NewReader(jsonData))
  323. },
  324. Expected: func(t *testing.T, resp *http.Response) {
  325. contentType := resp.Header.Get("Content-Type")
  326. if contentType != "application/json; charset=utf-8" {
  327. t.Errorf("expected content type application/json; charset=utf-8, got %s", contentType)
  328. }
  329. body, err := io.ReadAll(resp.Body)
  330. if err != nil {
  331. t.Fatalf("failed to read response body: %v", err)
  332. }
  333. var showResp api.ShowResponse
  334. err = json.Unmarshal(body, &showResp)
  335. if err != nil {
  336. t.Fatalf("failed to unmarshal response body: %v", err)
  337. }
  338. var params []string
  339. paramsSplit := strings.Split(showResp.Parameters, "\n")
  340. for _, p := range paramsSplit {
  341. params = append(params, strings.Join(strings.Fields(p), " "))
  342. }
  343. sort.Strings(params)
  344. expectedParams := []string{
  345. "seed 42",
  346. "stop \"bar\"",
  347. "stop \"foo\"",
  348. "top_p 0.9",
  349. }
  350. if !equalStringSlices(params, expectedParams) {
  351. t.Errorf("expected parameters %v, got %v", expectedParams, params)
  352. }
  353. paramCount, ok := showResp.ModelInfo["general.parameter_count"].(float64)
  354. if !ok {
  355. t.Fatalf("expected parameter count to be a float64, got %T", showResp.ModelInfo["general.parameter_count"])
  356. }
  357. if math.Abs(paramCount) > 1e-9 {
  358. t.Errorf("expected parameter count to be 0, got %f", paramCount)
  359. }
  360. },
  361. },
  362. {
  363. Name: "openai retrieve model handler",
  364. Method: http.MethodGet,
  365. Path: "/v1/models/show-model",
  366. Expected: func(t *testing.T, resp *http.Response) {
  367. contentType := resp.Header.Get("Content-Type")
  368. if contentType != "application/json" {
  369. t.Errorf("expected content type application/json, got %s", contentType)
  370. }
  371. body, err := io.ReadAll(resp.Body)
  372. if err != nil {
  373. t.Fatalf("failed to read response body: %v", err)
  374. }
  375. var retrieveResp api.RetrieveModelResponse
  376. err = json.Unmarshal(body, &retrieveResp)
  377. if err != nil {
  378. t.Fatalf("failed to unmarshal response body: %v", err)
  379. }
  380. if retrieveResp.Id != "show-model" || retrieveResp.OwnedBy != "library" {
  381. t.Errorf("expected model 'show-model' owned by 'library', got %v", retrieveResp)
  382. }
  383. },
  384. },
  385. }
  386. t.Setenv("OLLAMA_MODELS", t.TempDir())
  387. s := &Server{}
  388. router := s.GenerateRoutes()
  389. httpSrv := httptest.NewServer(router)
  390. t.Cleanup(httpSrv.Close)
  391. for _, tc := range testCases {
  392. t.Run(tc.Name, func(t *testing.T) {
  393. u := httpSrv.URL + tc.Path
  394. req, err := http.NewRequestWithContext(context.TODO(), tc.Method, u, nil)
  395. if err != nil {
  396. t.Fatalf("failed to create request: %v", err)
  397. }
  398. if tc.Setup != nil {
  399. tc.Setup(t, req)
  400. }
  401. resp, err := httpSrv.Client().Do(req)
  402. if err != nil {
  403. t.Fatalf("failed to do request: %v", err)
  404. }
  405. defer resp.Body.Close()
  406. if tc.Expected != nil {
  407. tc.Expected(t, resp)
  408. }
  409. })
  410. }
  411. }
  412. func casingShuffle(s string) string {
  413. rr := []rune(s)
  414. for i := range rr {
  415. if rand.N(2) == 0 {
  416. rr[i] = unicode.ToUpper(rr[i])
  417. } else {
  418. rr[i] = unicode.ToLower(rr[i])
  419. }
  420. }
  421. return string(rr)
  422. }
  423. func TestManifestCaseSensitivity(t *testing.T) {
  424. t.Setenv("OLLAMA_MODELS", t.TempDir())
  425. r := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  426. w.WriteHeader(http.StatusOK)
  427. io.WriteString(w, `{}`) //nolint:errcheck
  428. }))
  429. defer r.Close()
  430. nameUsed := make(map[string]bool)
  431. name := func() string {
  432. const fqmn = "example/namespace/model:tag"
  433. for {
  434. v := casingShuffle(fqmn)
  435. if nameUsed[v] {
  436. continue
  437. }
  438. nameUsed[v] = true
  439. return v
  440. }
  441. }
  442. wantStableName := name()
  443. // checkManifestList tests that there is strictly one manifest in the
  444. // models directory, and that the manifest is for the model under test.
  445. checkManifestList := func() {
  446. t.Helper()
  447. mandir := filepath.Join(os.Getenv("OLLAMA_MODELS"), "manifests/")
  448. var entries []string
  449. t.Logf("dir entries:")
  450. fsys := os.DirFS(mandir)
  451. err := fs.WalkDir(fsys, ".", func(path string, info fs.DirEntry, err error) error {
  452. if err != nil {
  453. return err
  454. }
  455. t.Logf(" %s", fs.FormatDirEntry(info))
  456. if info.IsDir() {
  457. return nil
  458. }
  459. path = strings.TrimPrefix(path, mandir)
  460. entries = append(entries, path)
  461. return nil
  462. })
  463. if err != nil {
  464. t.Fatalf("failed to walk directory: %v", err)
  465. }
  466. if len(entries) != 1 {
  467. t.Errorf("len(got) = %d, want 1", len(entries))
  468. return // do not use Fatal so following steps run
  469. }
  470. g := entries[0] // raw path
  471. g = filepath.ToSlash(g)
  472. w := model.ParseName(wantStableName).Filepath()
  473. w = filepath.ToSlash(w)
  474. if g != w {
  475. t.Errorf("\ngot: %s\nwant: %s", g, w)
  476. }
  477. }
  478. checkOK := func(w *httptest.ResponseRecorder) {
  479. t.Helper()
  480. if w.Code != http.StatusOK {
  481. t.Errorf("code = %d, want 200", w.Code)
  482. t.Logf("body: %s", w.Body.String())
  483. }
  484. }
  485. var s Server
  486. testMakeRequestDialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
  487. var d net.Dialer
  488. return d.DialContext(ctx, "tcp", r.Listener.Addr().String())
  489. }
  490. t.Cleanup(func() { testMakeRequestDialContext = nil })
  491. t.Logf("creating")
  492. checkOK(createRequest(t, s.CreateHandler, api.CreateRequest{
  493. // Start with the stable name, and later use a case-shuffled
  494. // version.
  495. Name: wantStableName,
  496. Modelfile: fmt.Sprintf("FROM %s", createBinFile(t, nil, nil)),
  497. Stream: &stream,
  498. }))
  499. checkManifestList()
  500. t.Logf("creating (again)")
  501. checkOK(createRequest(t, s.CreateHandler, api.CreateRequest{
  502. Name: name(),
  503. Modelfile: fmt.Sprintf("FROM %s", createBinFile(t, nil, nil)),
  504. Stream: &stream,
  505. }))
  506. checkManifestList()
  507. t.Logf("pulling")
  508. checkOK(createRequest(t, s.PullHandler, api.PullRequest{
  509. Name: name(),
  510. Stream: &stream,
  511. Insecure: true,
  512. }))
  513. checkManifestList()
  514. t.Logf("copying")
  515. checkOK(createRequest(t, s.CopyHandler, api.CopyRequest{
  516. Source: name(),
  517. Destination: name(),
  518. }))
  519. checkManifestList()
  520. }
  521. func TestShow(t *testing.T) {
  522. t.Setenv("OLLAMA_MODELS", t.TempDir())
  523. var s Server
  524. createRequest(t, s.CreateHandler, api.CreateRequest{
  525. Name: "show-model",
  526. Modelfile: fmt.Sprintf(
  527. "FROM %s\nFROM %s",
  528. createBinFile(t, llm.KV{"general.architecture": "test"}, nil),
  529. createBinFile(t, llm.KV{"general.type": "projector", "general.architecture": "clip"}, nil),
  530. ),
  531. })
  532. w := createRequest(t, s.ShowHandler, api.ShowRequest{
  533. Name: "show-model",
  534. })
  535. if w.Code != http.StatusOK {
  536. t.Fatalf("expected status code 200, actual %d", w.Code)
  537. }
  538. var resp api.ShowResponse
  539. if err := json.NewDecoder(w.Body).Decode(&resp); err != nil {
  540. t.Fatal(err)
  541. }
  542. if resp.ModelInfo["general.architecture"] != "test" {
  543. t.Fatal("Expected model architecture to be 'test', but got", resp.ModelInfo["general.architecture"])
  544. }
  545. if resp.ProjectorInfo["general.architecture"] != "clip" {
  546. t.Fatal("Expected projector architecture to be 'clip', but got", resp.ProjectorInfo["general.architecture"])
  547. }
  548. }
  549. func TestNormalize(t *testing.T) {
  550. type testCase struct {
  551. input []float32
  552. }
  553. testCases := []testCase{
  554. {input: []float32{1}},
  555. {input: []float32{0, 1, 2, 3}},
  556. {input: []float32{0.1, 0.2, 0.3}},
  557. {input: []float32{-0.1, 0.2, 0.3, -0.4}},
  558. {input: []float32{0, 0, 0}},
  559. }
  560. isNormalized := func(vec []float32) (res bool) {
  561. sum := 0.0
  562. for _, v := range vec {
  563. sum += float64(v * v)
  564. }
  565. if math.Abs(sum-1) > 1e-6 {
  566. return sum == 0
  567. } else {
  568. return true
  569. }
  570. }
  571. for _, tc := range testCases {
  572. t.Run("", func(t *testing.T) {
  573. normalized := normalize(tc.input)
  574. if !isNormalized(normalized) {
  575. t.Errorf("Vector %v is not normalized", tc.input)
  576. }
  577. })
  578. }
  579. }
  580. func TestVersionHandler(t *testing.T) {
  581. w := httptest.NewRecorder()
  582. req, _ := http.NewRequest(http.MethodGet, "/api/version", nil)
  583. s := &Server{}
  584. s.versionHandler(w, req)
  585. if w.Code != http.StatusOK {
  586. t.Fatalf("Expected status code %d, but got %d", http.StatusOK, w.Code)
  587. }
  588. ct := w.Header().Get("Content-Type")
  589. if ct != "application/json" {
  590. t.Fatalf("Expected content type application/json, but got %s", ct)
  591. }
  592. var resp struct {
  593. Version string `json:"version"`
  594. }
  595. if err := json.NewDecoder(w.Body).Decode(&resp); err != nil {
  596. t.Fatal(err)
  597. }
  598. if resp.Version != version.Version {
  599. t.Fatalf("want version %s, got %s", version.Version, resp.Version)
  600. }
  601. w = httptest.NewRecorder()
  602. req, _ = http.NewRequest(http.MethodPost, "/api/version", nil)
  603. s.versionHandler(w, req)
  604. if w.Code != http.StatusMethodNotAllowed {
  605. t.Fatalf("Expected status code %d, but got %d", http.StatusMethodNotAllowed, w.Code)
  606. }
  607. }