Skip to content

Commit

Permalink
chore: embed version in test too (#1926)
Browse files Browse the repository at this point in the history
This change is a simple resolution to a build configuration error in google3.

Also, fix two docstring lints.
  • Loading branch information
enocom committed Aug 22, 2023
1 parent 31ae14b commit f0ae360
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
4 changes: 2 additions & 2 deletions proxy/util/cloudsqlutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var versionString string
// metadataString indicates additional build or distribution metadata.
var metadataString = ""

// semanticVersion returns the version of the proxy in a semver format.
// SemanticVersion returns the version of the proxy in a semver format.
func SemanticVersion() string {
v := strings.TrimSpace(versionString)
if metadataString != "" {
Expand All @@ -65,7 +65,7 @@ func SemanticVersion() string {
return v
}

// userAgentFromVersionString returns an appropriate user agent string
// UserAgentFromVersionString returns an appropriate user agent string
// for identifying this proxy process.
func UserAgentFromVersionString() string {
return "cloud_sql_proxy/" + SemanticVersion()
Expand Down
17 changes: 6 additions & 11 deletions proxy/util/cloudsqlutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,24 @@
package util

import (
"os"
_ "embed"
"strings"
"testing"
)

//go:embed version.txt
var actualVersion string

func TestSemanticVersion(t *testing.T) {
v, err := os.ReadFile("version.txt")
if err != nil {
t.Fatalf("failed to read version.txt: %v", err)
}
want := strings.TrimSpace(string(v))
want := strings.TrimSpace(actualVersion)

if got := SemanticVersion(); got != want {
t.Fatalf("want = %q, got = %q", want, got)
}
}

func TestUserAgentFromVersionString(t *testing.T) {
v, err := os.ReadFile("version.txt")
if err != nil {
t.Fatalf("failed to read version.txt: %v", err)
}
want := "cloud_sql_proxy/" + strings.TrimSpace(string(v))
want := "cloud_sql_proxy/" + strings.TrimSpace(actualVersion)

if got := UserAgentFromVersionString(); got != want {
t.Fatalf("want = %q, got = %q", want, got)
Expand Down

0 comments on commit f0ae360

Please sign in to comment.