Files
magpie/internal/provider/google_env_comment_test.go
T
Charan Rathore b643231fc7 edit, provider: stop inline comments leaking into dotenv values (#439)
* edit,provider: stop reading inline comments as part of dotenv values

* provider: read Google env values through edit.GetEnvFile
2026-10-02 00:57:41 +08:00

33 lines
928 B
Go

package provider
import (
"os"
"path/filepath"
"testing"
)
func TestGoogleEnvInlineComment(t *testing.T) {
p := filepath.Join(t.TempDir(), ".env")
os.WriteFile(p, []byte("GOOGLE_CLOUD_PROJECT=my-project-123 # work project\n"), 0o600)
if got := envFileValue(p, "GOOGLE_CLOUD_PROJECT"); got != "my-project-123" {
t.Fatalf("got %q", got)
}
}
func TestEnvFileValueQuotedInlineComment(t *testing.T) {
for _, tc := range []struct{ name, line, want string }{
{"double quoted", `GOOGLE_CLOUD_PROJECT="my-proj" # work`, "my-proj"},
{"single quoted hash", `GOOGLE_CLOUD_PROJECT='a#b' # c`, "a#b"},
} {
t.Run(tc.name, func(t *testing.T) {
p := filepath.Join(t.TempDir(), ".env")
if err := os.WriteFile(p, []byte(tc.line+"\n"), 0o600); err != nil {
t.Fatal(err)
}
if got := envFileValue(p, "GOOGLE_CLOUD_PROJECT"); got != tc.want {
t.Fatalf("envFileValue = %q, want %q", got, tc.want)
}
})
}
}