github.com/prebid/prebid-server/v2@v2.18.0/endpoints/version_test.go (about) 1 package endpoints 2 3 import ( 4 "io" 5 "net/http/httptest" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestVersion(t *testing.T) { 12 var testCases = []struct { 13 description string 14 version string 15 revision string 16 expected string 17 }{ 18 { 19 description: "Empty", 20 version: "", 21 revision: "", 22 expected: `{"revision":"not-set","version":"not-set"}`, 23 }, 24 { 25 description: "Version Only", 26 version: "1.2.3", 27 revision: "", 28 expected: `{"revision":"not-set","version":"1.2.3"}`, 29 }, 30 { 31 description: "Revision Only", 32 version: "", 33 revision: "d6cd1e2bd19e03a81132a23b2025920577f84e37", 34 expected: `{"revision":"d6cd1e2bd19e03a81132a23b2025920577f84e37","version":"not-set"}`, 35 }, 36 { 37 description: "Fully Populated", 38 version: "1.2.3", 39 revision: "d6cd1e2bd19e03a81132a23b2025920577f84e37", 40 expected: `{"revision":"d6cd1e2bd19e03a81132a23b2025920577f84e37","version":"1.2.3"}`, 41 }, 42 } 43 44 for _, test := range testCases { 45 handler := NewVersionEndpoint(test.version, test.revision) 46 w := httptest.NewRecorder() 47 48 handler(w, nil) 49 50 response, err := io.ReadAll(w.Result().Body) 51 if assert.NoError(t, err, test.description+":read") { 52 assert.JSONEq(t, test.expected, string(response), test.description+":response") 53 } 54 } 55 }