MCPcopy Create free account
hub / github.com/github/gh-aw / TestYamlStringValue

Function TestYamlStringValue

pkg/workflow/engine_helpers_test.go:380–426  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

378}
379
380func TestYamlStringValue(t *testing.T) {
381 tests := []struct {
382 name string
383 input string
384 expected string
385 }{
386 {
387 name: "plain string unchanged",
388 input: "hello world",
389 expected: "hello world",
390 },
391 {
392 name: "empty string unchanged",
393 input: "",
394 expected: "",
395 },
396 {
397 name: "github actions expression unchanged",
398 input: "${{ secrets.TOKEN }}",
399 expected: "${{ secrets.TOKEN }}",
400 },
401 {
402 name: "json object gets single-quoted",
403 input: `{"key":"value"}`,
404 expected: `'{"key":"value"}'`,
405 },
406 {
407 name: "json array gets single-quoted",
408 input: `["a","b"]`,
409 expected: `'["a","b"]'`,
410 },
411 {
412 name: "json object with embedded single quote gets escaped",
413 input: `{"key":"it's"}`,
414 expected: `'{"key":"it''s"}'`,
415 },
416 }
417
418 for _, tt := range tests {
419 t.Run(tt.name, func(t *testing.T) {
420 result := yamlStringValue(tt.input)
421 if result != tt.expected {
422 t.Errorf("yamlStringValue(%q) = %q, want %q", tt.input, result, tt.expected)
423 }
424 })
425 }
426}
427
428func TestFormatStepWithCommandAndEnvYAMLSafe(t *testing.T) {
429 t.Run("json env var is single-quoted for valid YAML", func(t *testing.T) {

Callers

nothing calls this directly

Calls 3

yamlStringValueFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected