MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / TestVersion

Function TestVersion

tests/other_test.go:27–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestVersion(t *testing.T) {
28 ctx := context.Background()
29
30 data, err := os.ReadFile("../cmd/version.txt")
31 if err != nil {
32 t.Fatalf("failed to read version.txt: %v", err)
33 }
34 want := strings.TrimSpace(string(data))
35
36 // Start the proxy
37 p, err := StartProxy(ctx, "--version")
38 if err != nil {
39 t.Fatalf("proxy start failed: %v", err)
40 }
41 defer p.Close()
42
43 // Assume the proxy should be able to print "version" relatively quickly
44 ctx, cancel := context.WithTimeout(ctx, 50*time.Millisecond)
45 defer cancel()
46 err = p.Wait(ctx)
47 if err != nil {
48 t.Fatalf("proxy exited unexpectedly: %v", err)
49 }
50 output, err := bufio.NewReader(p.Out).ReadString('\n')
51 if err != nil {
52 t.Fatalf("failed to read output from proxy: %v", err)
53 }
54 if !strings.Contains(output, want) {
55 t.Errorf("proxy did not return correct version: want %q, got %q", want, output)
56 }
57}

Callers

nothing calls this directly

Calls 4

StartProxyFunction · 0.85
WaitMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected