cuelang.org/go@v0.10.1/internal/cueversion/version_test.go (about) 1 package cueversion 2 3 import ( 4 "io" 5 "net/http" 6 "net/http/httptest" 7 "testing" 8 9 "github.com/go-quicktest/qt" 10 ) 11 12 func TestModuleVersion(t *testing.T) { 13 // This is just a smoke test to make sure that things 14 // are wired up OK. It would be possible to unit 15 // test the logic inside Version, but it's simple 16 // enough that that would amount to creating invariants 17 // that just match the code, not providing any more 18 // assurance of correctness. 19 vers := ModuleVersion() 20 qt.Assert(t, qt.Not(qt.Equals(vers, ""))) 21 } 22 23 func TestUserAgent(t *testing.T) { 24 agent := UserAgent("custom") 25 qt.Assert(t, qt.Matches(agent, 26 `Cue/[^ ]+ \(custom; lang v[^)]+\) Go/[^ ]+ \([^/]+/[^/]+\)`, 27 )) 28 } 29 30 func TestTransport(t *testing.T) { 31 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { 32 w.Write([]byte(req.UserAgent())) 33 })) 34 defer srv.Close() 35 client := &http.Client{ 36 Transport: NewTransport("foo", nil), 37 } 38 resp, err := client.Get(srv.URL) 39 qt.Assert(t, qt.IsNil(err)) 40 defer resp.Body.Close() 41 data, err := io.ReadAll(resp.Body) 42 qt.Assert(t, qt.IsNil(err)) 43 qt.Assert(t, qt.Matches(string(data), `Cue/[^ ]+ \(foo; lang v[^)]+\) Go/[^ ]+ \([^/]+/[^/]+\)`)) 44 }