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

Function TestActionCacheInputs

pkg/workflow/action_cache_test.go:639–703  ·  view source on GitHub ↗

TestActionCacheInputs tests caching and retrieving action inputs

(t *testing.T)

Source from the content-addressed store, hash-verified

637
638// TestActionCacheInputs tests caching and retrieving action inputs
639func TestActionCacheInputs(t *testing.T) {
640 tmpDir := testutil.TempDir(t, "test-*")
641 cache := NewActionCache(tmpDir)
642 cache.Set("owner/repo", "v1", "abc123sha456789012345678901234567890123")
643
644 // Initially no inputs cached
645 inputs, ok := cache.GetInputs("owner/repo", "v1")
646 if ok {
647 t.Error("Expected no cached inputs, got some")
648 }
649 if inputs != nil {
650 t.Error("Expected nil inputs, got non-nil")
651 }
652
653 // Store inputs
654 toCache := map[string]*ActionYAMLInput{
655 "labels": {Description: "Labels to add.", Required: true},
656 "number": {Description: "PR number."},
657 }
658 cache.SetInputs("owner/repo", "v1", toCache)
659
660 // Retrieve inputs
661 inputs, ok = cache.GetInputs("owner/repo", "v1")
662 if !ok {
663 t.Fatal("Expected cached inputs to exist")
664 }
665 if len(inputs) != 2 {
666 t.Errorf("Expected 2 inputs, got %d", len(inputs))
667 }
668 if inputs["labels"] == nil || !inputs["labels"].Required {
669 t.Error("Expected 'labels' input to be required")
670 }
671
672 // Set with the SAME SHA - inputs must be preserved
673 cache.Set("owner/repo", "v1", "abc123sha456789012345678901234567890123")
674 inputs, ok = cache.GetInputs("owner/repo", "v1")
675 if !ok {
676 t.Error("Expected inputs to survive Set() with same SHA")
677 }
678 if len(inputs) != 2 {
679 t.Errorf("Expected inputs to be preserved after Set() with same SHA, got %d", len(inputs))
680 }
681
682 // Set with a NEW SHA - inputs must be cleared (stale inputs no longer match pinned commit)
683 cache.Set("owner/repo", "v1", "newsha456789012345678901234567890123456")
684 inputs, ok = cache.GetInputs("owner/repo", "v1")
685 if ok {
686 t.Error("Expected inputs to be cleared after Set() with new SHA")
687 }
688 if inputs != nil {
689 t.Error("Expected nil inputs after SHA change, got non-nil")
690 }
691
692 // SetInputs on a missing key now creates a new entry
693 cache.SetInputs("owner/repo", "v99", map[string]*ActionYAMLInput{
694 "x": {Description: "x"},
695 })
696 inputs, ok = cache.GetInputs("owner/repo", "v99")

Callers

nothing calls this directly

Calls 7

SetMethod · 0.95
GetInputsMethod · 0.95
SetInputsMethod · 0.95
TempDirFunction · 0.92
NewActionCacheFunction · 0.85
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected