golang.org/x/build@v0.0.0-20240506185731-218518f32b70/internal/relui/metrics_test.go (about) 1 // Copyright 2022 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package relui 6 7 import "testing" 8 9 func TestQueryName(t *testing.T) { 10 cases := []struct { 11 desc string 12 query string 13 want string 14 }{ 15 { 16 desc: "named query", 17 query: "-- name: SelectOne :one\nSELECT 1;", 18 want: "SelectOne", 19 }, 20 { 21 desc: "empty string", 22 query: "", 23 want: "Unknown", 24 }, 25 { 26 desc: "missing name comment", 27 query: "SELECT 1\nLIMIT 1;", 28 want: "Unknown", 29 }, 30 } 31 for _, c := range cases { 32 t.Run(c.desc, func(t *testing.T) { 33 got := queryName(c.query) 34 if got != c.want { 35 t.Errorf("queryName(%q) = %q, wanted %q", c.query, got, c.want) 36 } 37 }) 38 } 39 }