Files
runtime/apps/daemon/pkg/git/service_test.go
zeekay ea80dc3638 feat: Add new Dockerfiles and improve containerization
- Add main Dockerfile for production builds
- Add Dockerfile.runtime for secure code execution
- Add Dockerfile.runtime.fixed with improved configuration
- Include .dockerignore for build optimization
- Add integration documentation and publishing guides
- Update API and CLI components for better runtime support
- Enhance sandbox and container management features
2025-08-16 23:03:39 -05:00

99 lines
3.5 KiB
Go

// Copyright 2025 Hanzo Industries Inc.
// SPDX-License-Identifier: AGPL-3.0
package git_test
import (
"testing"
"github.com/hanzoai/daemon/pkg/git"
"github.com/hanzoai/daemon/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/hanzoai/runtime",
Name: "runtime",
Branch: "main",
Target: gitprovider.CloneTargetBranch,
}
var repoHttps = &gitprovider.GitRepository{
Id: "123",
Url: "https://github.com/hanzoai/runtime",
Name: "runtime",
Branch: "main",
Target: gitprovider.CloneTargetBranch,
}
var repoWithoutProtocol = &gitprovider.GitRepository{
Id: "123",
Url: "github.com/hanzoai/runtime",
Name: "runtime",
Branch: "main",
Target: gitprovider.CloneTargetBranch,
}
var repoWithCloneTargetCommit = &gitprovider.GitRepository{
Id: "123",
Url: "https://github.com/hanzoai/runtime",
Name: "runtime",
Branch: "main",
Sha: "1234567890",
Target: gitprovider.CloneTargetCommit,
}
var creds = &http.BasicAuth{
Username: "hanzoai",
Password: "Runtime123",
}
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://hanzoai:[email protected]/hanzoai/runtime", "/workdir"}, cloneCmd)
cloneCmd = s.gitService.CloneRepositoryCmd(repoHttp, creds)
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "http://hanzoai:Runtime123@localhost:3000/hanzoai/runtime", "/workdir"}, cloneCmd)
cloneCmd = s.gitService.CloneRepositoryCmd(repoWithoutProtocol, creds)
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://hanzoai:[email protected]/hanzoai/runtime", "/workdir"}, cloneCmd)
cloneCmd = s.gitService.CloneRepositoryCmd(repoWithCloneTargetCommit, creds)
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://hanzoai:[email protected]/hanzoai/runtime", "/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/hanzoai/runtime", "/workdir"}, cloneCmd)
cloneCmd = s.gitService.CloneRepositoryCmd(repoHttp, nil)
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "http://localhost:3000/hanzoai/runtime", "/workdir"}, cloneCmd)
cloneCmd = s.gitService.CloneRepositoryCmd(repoWithoutProtocol, nil)
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://github.com/hanzoai/runtime", "/workdir"}, cloneCmd)
cloneCmd = s.gitService.CloneRepositoryCmd(repoWithCloneTargetCommit, nil)
s.Require().Equal([]string{"git", "clone", "--single-branch", "--branch", "\"main\"", "https://github.com/hanzoai/runtime", "/workdir", "&&", "cd", "/workdir", "&&", "git", "checkout", "1234567890"}, cloneCmd)
}