-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support http protocol for git urls
Signed-off-by: Ivan Dagelic <dagelic.ivan@gmail.com>
- Loading branch information
Showing
2 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2024 Daytona Platforms Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package git_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/daytonaio/daytona/pkg/git" | ||
"github.com/daytonaio/daytona/pkg/gitprovider" | ||
"github.com/go-git/go-git/v5/plumbing/transport/http" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
var repoHttp = &gitprovider.GitRepository{ | ||
Id: "123", | ||
Url: "http://localhost:3000/daytonaio/daytona", | ||
Name: "daytona", | ||
Branch: "main", | ||
Target: gitprovider.CloneTargetBranch, | ||
} | ||
|
||
var repoHttps = &gitprovider.GitRepository{ | ||
Id: "123", | ||
Url: "https://github.com/daytonaio/daytona", | ||
Name: "daytona", | ||
Branch: "main", | ||
Target: gitprovider.CloneTargetBranch, | ||
} | ||
|
||
var repoWithoutProtocol = &gitprovider.GitRepository{ | ||
Id: "123", | ||
Url: "github.com/daytonaio/daytona", | ||
Name: "daytona", | ||
Branch: "main", | ||
Target: gitprovider.CloneTargetBranch, | ||
} | ||
|
||
var repoWithCloneTargetCommit = &gitprovider.GitRepository{ | ||
Id: "123", | ||
Url: "https://github.com/daytonaio/daytona", | ||
Name: "daytona", | ||
Branch: "main", | ||
Sha: "1234567890", | ||
Target: gitprovider.CloneTargetCommit, | ||
} | ||
|
||
var creds = &http.BasicAuth{ | ||
Username: "daytonaio", | ||
Password: "Daytona123", | ||
} | ||
|
||
type GitServiceTestSuite struct { | ||
suite.Suite | ||
gitService git.IGitService | ||
} | ||
|
||
func NewGitServiceTestSuite() *GitServiceTestSuite { | ||
return &GitServiceTestSuite{} | ||
} | ||
|
||
func (s *GitServiceTestSuite) SetupTest() { | ||
s.gitService = &git.Service{ | ||
ProjectDir: "/workdir", | ||
} | ||
} | ||
|
||
func TestGitService(t *testing.T) { | ||
suite.Run(t, NewGitServiceTestSuite()) | ||
} | ||
|
||
func (s *GitServiceTestSuite) TestCloneRepositoryCmd_WithCreds() { | ||
cloneCmd := s.gitService.CloneRepositoryCmd(repoHttps, creds) | ||
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://daytonaio:Daytona123@github.com/daytonaio/daytona", "/workdir"}, cloneCmd) | ||
|
||
cloneCmd = s.gitService.CloneRepositoryCmd(repoHttp, creds) | ||
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "http://daytonaio:Daytona123@localhost:3000/daytonaio/daytona", "/workdir"}, cloneCmd) | ||
|
||
cloneCmd = s.gitService.CloneRepositoryCmd(repoWithoutProtocol, creds) | ||
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://daytonaio:Daytona123@github.com/daytonaio/daytona", "/workdir"}, cloneCmd) | ||
|
||
cloneCmd = s.gitService.CloneRepositoryCmd(repoWithCloneTargetCommit, creds) | ||
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://daytonaio:Daytona123@github.com/daytonaio/daytona", "/workdir", "&&", "cd", "/workdir", "&&", "git", "checkout", "1234567890"}, cloneCmd) | ||
} | ||
|
||
func (s *GitServiceTestSuite) TestCloneRepositoryCmd_WithoutCreds() { | ||
cloneCmd := s.gitService.CloneRepositoryCmd(repoHttps, nil) | ||
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://github.com/daytonaio/daytona", "/workdir"}, cloneCmd) | ||
|
||
cloneCmd = s.gitService.CloneRepositoryCmd(repoHttp, nil) | ||
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "http://localhost:3000/daytonaio/daytona", "/workdir"}, cloneCmd) | ||
|
||
cloneCmd = s.gitService.CloneRepositoryCmd(repoWithoutProtocol, nil) | ||
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://github.com/daytonaio/daytona", "/workdir"}, cloneCmd) | ||
|
||
cloneCmd = s.gitService.CloneRepositoryCmd(repoWithCloneTargetCommit, nil) | ||
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://github.com/daytonaio/daytona", "/workdir", "&&", "cd", "/workdir", "&&", "git", "checkout", "1234567890"}, cloneCmd) | ||
} |