-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GitService API to interface repo sync events (#14)
- Loading branch information
Showing
7 changed files
with
157 additions
and
18 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,39 @@ | ||
package core | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/switcherapi/switcher-gitops/src/model" | ||
) | ||
|
||
type IGitService interface { | ||
GetRepositoryData() (string, string, string) | ||
CheckForChanges(account model.Account, lastCommit string, date string, content string) (status string) | ||
} | ||
|
||
type GitService struct { | ||
RepoURL string | ||
Token string | ||
BranchName string | ||
} | ||
|
||
func NewGitService(repoURL string, token string, branchName string) *GitService { | ||
return &GitService{ | ||
RepoURL: repoURL, | ||
Token: token, | ||
BranchName: branchName, | ||
} | ||
} | ||
|
||
func (g *GitService) GetRepositoryData() (string, string, string) { | ||
lastCommit := "123" | ||
date := time.Now().Format(time.ANSIC) | ||
content := "Content" | ||
|
||
return lastCommit, date, content | ||
} | ||
|
||
func (g *GitService) CheckForChanges(account model.Account, lastCommit string, | ||
date string, content string) (status string) { | ||
return model.StatusSynced | ||
} |
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,49 @@ | ||
package core | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/switcherapi/switcher-gitops/src/model" | ||
) | ||
|
||
func TestNewGitService(t *testing.T) { | ||
// Given | ||
repoURL := "repoURL" | ||
token := "token" | ||
branchName := "main" | ||
|
||
// Test | ||
gitService := NewGitService(repoURL, token, branchName) | ||
|
||
// Assert | ||
assert.Equal(t, repoURL, gitService.RepoURL) | ||
assert.Equal(t, token, gitService.Token) | ||
assert.Equal(t, branchName, gitService.BranchName) | ||
} | ||
|
||
func TestGetRepositoryData(t *testing.T) { | ||
// Given | ||
gitService := NewGitService("repoURL", "token", "main") | ||
|
||
// Test | ||
lastCommit, date, content := gitService.GetRepositoryData() | ||
|
||
// Assert | ||
assert.NotEmpty(t, lastCommit) | ||
assert.NotEmpty(t, date) | ||
assert.NotEmpty(t, content) | ||
} | ||
|
||
func TestCheckForChanges(t *testing.T) { | ||
// Given | ||
gitService := NewGitService("repoURL", "token", "main") | ||
account := givenAccount() | ||
lastCommit, date, content := gitService.GetRepositoryData() | ||
|
||
// Test | ||
status := gitService.CheckForChanges(account, lastCommit, date, content) | ||
|
||
// Assert | ||
assert.Equal(t, model.StatusSynced, status) | ||
} |
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
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