github.com/go-kivik/kivik/v4@v4.3.2/x/kivikd/couchserver/root_test.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 12 13 //go:build !js 14 15 package couchserver 16 17 import ( 18 "net/http/httptest" 19 "testing" 20 21 "gitlab.com/flimzy/testy" 22 ) 23 24 func TestGetRoot(t *testing.T) { 25 h := Handler{ 26 CompatVersion: "1.6.1", 27 Vendor: "Acme", 28 VendorVersion: "10.0", 29 } 30 w := httptest.NewRecorder() 31 req := httptest.NewRequest("GET", "/", nil) 32 handler := h.GetRoot() 33 handler(w, req) 34 resp := w.Result() 35 defer resp.Body.Close() 36 expected := map[string]interface{}{ 37 "couchdb": "Välkommen", 38 "version": "1.6.1", 39 "vendor": map[string]string{ 40 "version": "10.0", 41 "name": "Acme", 42 }, 43 } 44 if d := testy.DiffAsJSON(expected, resp.Body); d != nil { 45 t.Error(d) 46 } 47 }