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

Function TestGenerateFetchStep

pkg/workflow/checkout_manager_test.go:913–1026  ·  view source on GitHub ↗

TestGenerateFetchStep verifies that the git fetch YAML step is generated correctly.

(t *testing.T)

Source from the content-addressed store, hash-verified

911
912// TestGenerateFetchStep verifies that the git fetch YAML step is generated correctly.
913func TestGenerateFetchStep(t *testing.T) {
914 t.Run("no fetch refs returns empty string", func(t *testing.T) {
915 entry := &resolvedCheckout{}
916 got := generateFetchStepLines(entry, 0)
917 assert.Empty(t, got, "empty fetchRefs should produce no step")
918 })
919
920 t.Run("fetch all branches uses star refspec", func(t *testing.T) {
921 entry := &resolvedCheckout{
922 fetchRefs: []string{"*"},
923 }
924 got := generateFetchStepLines(entry, 0)
925 assert.Contains(t, got, "Fetch additional refs", "should include step name")
926 assert.Contains(t, got, "+refs/heads/*:refs/remotes/origin/*", "should include correct refspec")
927 assert.Contains(t, got, "GH_AW_FETCH_TOKEN", "should set fetch token env var")
928 assert.Contains(t, got, "http.extraheader=Authorization:", "should configure credentials via http.extraheader")
929 // When no custom token set, falls back to the effective GitHub token chain
930 assert.Contains(t, got, "GH_AW_GITHUB_TOKEN", "should fall back to GH_AW token chain when no checkout token set")
931 // base64 must use -w 0 to prevent line wrapping with long tokens (e.g. fine-grained PATs)
932 assert.Contains(t, got, "base64 -w 0", "should use base64 -w 0 to disable line wrapping")
933 })
934
935 t.Run("fetch refs/pulls/open/* uses PR refspec", func(t *testing.T) {
936 entry := &resolvedCheckout{
937 fetchRefs: []string{"refs/pulls/open/*"},
938 }
939 got := generateFetchStepLines(entry, 0)
940 assert.Contains(t, got, "+refs/pull/*/head:refs/remotes/origin/pull/*/head", "should include PR refspec")
941 })
942
943 t.Run("custom token is used in fetch step", func(t *testing.T) {
944 entry := &resolvedCheckout{
945 fetchRefs: []string{"main"},
946 token: "${{ secrets.MY_PAT }}",
947 }
948 got := generateFetchStepLines(entry, 0)
949 assert.Contains(t, got, "${{ secrets.MY_PAT }}", "should use custom token from checkout config")
950 assert.NotContains(t, got, "github.token", "should not fall back to github.token when custom token set")
951 })
952
953 t.Run("repository name used in step name", func(t *testing.T) {
954 entry := &resolvedCheckout{
955 key: checkoutKey{repository: "owner/side-repo"},
956 fetchRefs: []string{"main"},
957 }
958 got := generateFetchStepLines(entry, 0)
959 assert.Contains(t, got, "Fetch additional refs for owner/side-repo", "should include repo in step name")
960 })
961
962 t.Run("non-root path uses -C flag", func(t *testing.T) {
963 entry := &resolvedCheckout{
964 key: checkoutKey{path: "libs/other"},
965 fetchRefs: []string{"main"},
966 }
967 got := generateFetchStepLines(entry, 0)
968 assert.Contains(t, got, `-C "${{ github.workspace }}/libs/other"`, "should use -C flag for non-root path")
969 })
970

Callers

nothing calls this directly

Calls 2

generateFetchStepLinesFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected