MCPcopy
hub / github.com/dagger/dagger / TestSubmoduleAuth

Method TestSubmoduleAuth

core/integration/git_test.go:1018–1122  ·  view source on GitHub ↗
(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

1016}
1017
1018func (GitSuite) TestSubmoduleAuth(ctx context.Context, t *testctx.T) {
1019 c := connect(ctx, t)
1020 t.Cleanup(func() { _ = c.Close() })
1021
1022 authToken := c.SetSecret("submodule-test-token", "test-token-"+identity.NewID())
1023
1024 submoduleContent := c.Directory().WithNewFile("submodule.txt", "This is the submodule content")
1025 parentContent := c.Directory().WithNewFile("parent.txt", "This is the parent content")
1026
1027 // Create bare parent + submodule repos in /srv
1028 // Git dance below is necessary: https://github.com/dagger/dagger/pull/10855#discussion_r2264174757
1029 gitReposCtr := c.Container().
1030 From(alpineImage).
1031 WithExec([]string{"apk", "add", "git"}).
1032 With(gitUserConfig).
1033 WithExec([]string{"sh", "-lc", "mkdir -p /srv && git init --bare /srv/submodule.git && git init --bare /srv/parent.git"}).
1034 WithDirectory("/tmp/sub", submoduleContent).
1035 WithExec([]string{"sh", "-lc", `
1036set -eux
1037cd /tmp/sub
1038git init
1039git add .
1040git commit -m 'Initial submodule commit'
1041git remote add origin file:///srv/submodule.git
1042git push -u origin main
1043`}).
1044 WithDirectory("/tmp/parent", parentContent).
1045 WithExec([]string{"sh", "-lc", `
1046set -eux
1047cd /tmp/parent
1048git init
1049git add .
1050git commit -m 'Initial parent commit'
1051git -c protocol.file.allow=always submodule add file:///srv/submodule.git sub
1052git commit -m 'Add submodule (absolute url to fetch)'
1053git config -f .gitmodules submodule.sub.url ../submodule.git
1054git add .gitmodules
1055git commit -m 'Make submodule URL relative'
1056git remote add origin file:///srv/parent.git
1057git push -u origin main
1058# dumb HTTP needs server-info
1059git --git-dir=/srv/submodule.git update-server-info
1060git --git-dir=/srv/parent.git update-server-info
1061`})
1062
1063 gitReposDir := gitReposCtr.Directory("/srv")
1064
1065 t.Run("smart-http", func(ctx context.Context, t *testctx.T) {
1066 gitSrv, base := gitSmartHTTPServiceDirAuth(ctx, t, c, "", gitReposDir, "", authToken)
1067 parentURL := base + "/parent.git"
1068
1069 t.Run("with auth", func(ctx context.Context, t *testctx.T) {
1070 tree := c.Git(parentURL, dagger.GitOpts{
1071 ExperimentalServiceHost: gitSrv,
1072 HTTPAuthToken: authToken,
1073 }).Branch("main").Tree()
1074
1075 txt, err := tree.File("parent.txt").Contents(ctx)

Callers

nothing calls this directly

Calls 15

NewIDFunction · 0.92
requireErrOutFunction · 0.85
httpServiceDirAuthFunction · 0.85
CleanupMethod · 0.80
connectFunction · 0.70
CloseMethod · 0.65
DirectoryMethod · 0.65
RunMethod · 0.65
TreeMethod · 0.65
FileMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected