Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ SWITCHER_API_URL=https://switcherapi.com/api/gitops-graphql
SWITCHER_API_JWT_SECRET=[YOUR_JWT_SECRET]

# Only for testing purposes. Values are loaded from accounts
GIT_TOKEN=[GIT_TOKEN]
GIT_REPO_URL=[GIT_REPO_URL]
GIT_BRANCH=[GIT_BRANCH]
GIT_TOKEN=
GIT_REPO_URL=https://github.com/switcherapi/switcher-gitops-fixture
GIT_BRANCH=main
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,25 @@ GitOps Domain Snapshot Orchestrator for Switcher API
# Features
- Manage Switchers with GitOps driven environment
- Multiple and independent Environments
- Auto Sync enables a fully integrated environment with Switcher API Management, Slack App and GitOps working simultaneously
- Auto Sync enables a fully integrated environment with Switcher API Management, Slack App and GitOps working simultaneously

# Integrated tests

This project does not run integration test without a valid GitOps repository settings.

In order to run integration tests locally, you need to create a valid GitOps repository with the following structure:

```bash
├── resources
│ ├── default.json (*)
```
(*) see a Switcher snapshot sample [here](https://github.com/switcherapi/switcher-gitops/blob/master/resources/default.json)

The next step is to set up PAT (Personal Access Token) for Switcher GitOps to access the repository. You can either create a fine-grained token with only the necessary permissions such as Content (Read and Write) and Metadata (Read) or use a personal token with full access.

Once you have the token, you can set it up in the `.env.test` environment file by including the following:
```bash
GIT_TOKEN=[YOUR_GIT_TOKEN]
GIT_REPO_URL=[YOUR_GIT_REPO_URL]
GIT_BRANCH=[YOUR_GIT_BRANCH]
```
49 changes: 49 additions & 0 deletions resources/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"domain": {
"group": [
{
"name": "Release 1",
"description": "Showcase configuration",
"activated": true,
"config": [
{
"key": "MY_SWITCHER_1",
"description": "My first switcher",
"activated": true,
"strategies": [
{
"strategy": "VALUE_VALIDATION",
"activated": false,
"operation": "EXIST",
"values": [
"user_1"
]
}
],
"components": [
"switcher-playground"
]
},
{
"key": "MY_SWITCHER_2",
"description": "",
"activated": false,
"strategies": [],
"components": [
"switcher-playground"
]
},
{
"key": "MY_SWITCHER_3",
"description": "",
"activated": true,
"strategies": [],
"components": [
"benchmark"
]
}
]
}
]
}
}
1 change: 0 additions & 1 deletion src/core/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func NewGitService(repoURL string, token string, branchName string) *GitService
}

func (g *GitService) GetRepositoryData(environment string) (string, string, string, error) {
println("GetRepositoryData")
commitHash, commitDate, content, err := g.getLastCommitData(model.FilePath + environment + ".json")

if err != nil {
Expand Down
26 changes: 26 additions & 0 deletions src/core/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/switcherapi/switcher-gitops/src/model"
)

const (
SkipMessage = "Skipping tests because environment variables are not set"
)

func TestNewGitService(t *testing.T) {
// Given
repoURL := "repoURL"
Expand All @@ -24,6 +28,10 @@ func TestNewGitService(t *testing.T) {
}

func TestGetRepositoryData(t *testing.T) {
if !canRunTests() {
t.Skip(SkipMessage)
}

// Given
gitService := NewGitService(
config.GetEnv("GIT_REPO_URL"),
Expand All @@ -41,6 +49,10 @@ func TestGetRepositoryData(t *testing.T) {
}

func TestGetRepositoryDataErrorInvalidEnvironment(t *testing.T) {
if !canRunTests() {
t.Skip(SkipMessage)
}

// Given
gitService := NewGitService(
config.GetEnv("GIT_REPO_URL"),
Expand All @@ -58,6 +70,10 @@ func TestGetRepositoryDataErrorInvalidEnvironment(t *testing.T) {
}

func TestGetRepositoryDataErrorInvalidToken(t *testing.T) {
if !canRunTests() {
t.Skip(SkipMessage)
}

// Given
gitService := NewGitService(
config.GetEnv("GIT_REPO_URL"),
Expand All @@ -75,6 +91,10 @@ func TestGetRepositoryDataErrorInvalidToken(t *testing.T) {
}

func TestCheckForChanges(t *testing.T) {
if !canRunTests() {
t.Skip(SkipMessage)
}

// Given
gitService := NewGitService(
config.GetEnv("GIT_REPO_URL"),
Expand All @@ -91,3 +111,9 @@ func TestCheckForChanges(t *testing.T) {
assert.Equal(t, model.StatusSynced, status)
assert.Equal(t, "Synced successfully", message)
}

// Helpers

func canRunTests() bool {
return config.GetEnv("GIT_REPO_URL") != "" && config.GetEnv("GIT_TOKEN") != "" && config.GetEnv("GIT_BRANCH") != ""
}