34 lines
722 B
Go
34 lines
722 B
Go
package service_definition
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type MockGit struct {
|
|
calls []string
|
|
}
|
|
|
|
func (g *MockGit) Clone(path string, destination string) (string, error) {
|
|
g.calls = append(g.calls, path+":"+destination)
|
|
|
|
return path, nil
|
|
}
|
|
|
|
func TestGetDefinitionGetDefinitionFromGit(t *testing.T) {
|
|
var gitFetcher GitDefinitionFetcher
|
|
|
|
fetcher, _ := NewDefinitionFetcher("git")
|
|
|
|
gitFetcher, _ = fetcher.(GitDefinitionFetcher)
|
|
|
|
mockGit := MockGit{}
|
|
gitFetcher.Git = &mockGit
|
|
|
|
mockUrl := "https://git.com/owner/repo.git"
|
|
gitFetcher.GetDefinition("git+" + mockUrl)
|
|
|
|
if !strings.HasPrefix(mockGit.calls[0], mockUrl) {
|
|
t.Errorf("Expected git cloning for %s, got %s instead.", mockUrl, mockGit.calls[0])
|
|
}
|
|
}
|