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

Function TestValidateMountEntries

pkg/workflow/validation_helpers_test.go:593–701  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

591}
592
593func TestValidateMountEntries(t *testing.T) {
594 t.Run("returns nil and calls onValid for each mount when all are valid", func(t *testing.T) {
595 var validated []mountParts
596 err := validateMountEntries(
597 []string{
598 "/host/a:/a:ro",
599 "/host/b:/b:rw",
600 },
601 func(_ int, parts mountParts) {
602 validated = append(validated, parts)
603 },
604 func(i int, mount string, parts mountParts, kind mountValidationKind) error {
605 return fmt.Errorf("unexpected invalid mount at %d: %s (%v) %#v", i, mount, kind, parts)
606 },
607 )
608
609 require.NoError(t, err)
610 assert.Equal(t, []mountParts{
611 {source: "/host/a", dest: "/a", mode: "ro"},
612 {source: "/host/b", dest: "/b", mode: "rw"},
613 }, validated)
614 })
615
616 t.Run("returns nil for empty mounts", func(t *testing.T) {
617 err := validateMountEntries(
618 nil,
619 func(_ int, _ mountParts) { t.Fatal("onValid should not be called") },
620 func(i int, mount string, parts mountParts, kind mountValidationKind) error {
621 return fmt.Errorf("onInvalid should not be called at %d: %s (%v) %#v", i, mount, kind, parts)
622 },
623 )
624
625 require.NoError(t, err)
626 })
627
628 t.Run("reports index 0 when first mount is invalid", func(t *testing.T) {
629 err := validateMountEntries(
630 []string{"/host/data:/data:nope"},
631 nil,
632 func(i int, mount string, parts mountParts, kind mountValidationKind) error {
633 assert.Equal(t, 0, i)
634 assert.Equal(t, "/host/data:/data:nope", mount)
635 assert.Equal(t, mountValidationModeError, kind)
636 assert.Equal(t, mountParts{source: "/host/data", dest: "/data", mode: "nope"}, parts)
637 return fmt.Errorf("invalid at %d", i)
638 },
639 )
640
641 require.EqualError(t, err, "invalid at 0")
642 })
643
644 t.Run("returns first invalid mount after valid prefix", func(t *testing.T) {
645 var validated []mountParts
646 err := validateMountEntries(
647 []string{
648 "/host/data:/data:ro",
649 "/host/data:/data:nope",
650 "/host/other:/other:rw",

Callers

nothing calls this directly

Calls 3

validateMountEntriesFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected