-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f04f1f
commit 425593c
Showing
21 changed files
with
376 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Unit Tests | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
jobs: | ||
build-format: | ||
name: Build and Format | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.19 | ||
|
||
- name: Install Executable to $GOPATH/bin | ||
run: go install | ||
|
||
- name: Run Tests | ||
run: go test -v ./tests/... |
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 |
---|---|---|
|
@@ -47,3 +47,6 @@ candy | |
|
||
.env | ||
dist/ | ||
output.json | ||
output.yaml | ||
output.yml |
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
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,28 @@ | ||
package docker | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestDockerCmd(t *testing.T) { | ||
|
||
expectedOutput := "Docker related commands." | ||
|
||
// it should convert a key-value file to json | ||
cmd := exec.Command("candy", "docker") | ||
|
||
// Capture the output | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Errorf("expected no error, but got: %v", err) | ||
} | ||
|
||
// Validate the cli output | ||
got := strings.TrimSpace(string(output)[:24]) | ||
if got != expectedOutput { | ||
t.Errorf("expected %v, but got: %v", expectedOutput, got) | ||
} | ||
|
||
} |
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,55 @@ | ||
package test | ||
|
||
import ( | ||
"encoding/base64" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// Test encode command | ||
func TestEncodeCmd(t *testing.T) { | ||
stringToEncode := "password" | ||
|
||
// Execute the encode command | ||
cmd := exec.Command("candy", "encode", stringToEncode) | ||
|
||
// Capture the output | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Errorf("expected no error, but got: %v", err) | ||
} | ||
|
||
// Validate the output | ||
expectedOutput := base64.StdEncoding.EncodeToString([]byte(stringToEncode)) | ||
got := strings.TrimSpace(string(output)) // Convert output to string and remove leading/trailing spaces | ||
if got != expectedOutput { | ||
t.Errorf("expected %v, but got: %v", expectedOutput, got) | ||
} | ||
} | ||
|
||
// Test decode flag | ||
func TestEncodeCmdWithDecode(t *testing.T) { | ||
stringToDecode := "cGFzc3dvcmQ=" | ||
|
||
// Execute the encode command | ||
cmd := exec.Command("candy", "encode", "-d", stringToDecode) | ||
|
||
// Capture the output | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Errorf("expected no error, but got: %v", err) | ||
} | ||
|
||
// Validate the output | ||
expectedOutput, err := base64.StdEncoding.DecodeString(stringToDecode) | ||
if err != nil { | ||
t.Errorf("expected no error, but got: %v", err) | ||
} | ||
|
||
got := strings.TrimSpace(string(output)) | ||
if got != string(expectedOutput) { | ||
t.Errorf("expected %v, but got: %v", string(expectedOutput), got) | ||
} | ||
|
||
} |
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 test | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestJsonToYamlCmd(t *testing.T) { | ||
|
||
// it should convert a json file to yaml | ||
|
||
// Execute the jsonToYaml command | ||
cmd := exec.Command("candy", "JTY", "-f", "testdata/JTY.json") | ||
|
||
// Capture the output | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Errorf("expected no error, but got: %v", err) | ||
} | ||
|
||
// Validate the cli output | ||
expecredOutput := "Operation completed successfully. Check the output.yaml file." | ||
got := strings.TrimSpace(string(output)) | ||
if got != expecredOutput { | ||
t.Errorf("expected %v, but got: %v", expecredOutput, got) | ||
} | ||
|
||
// Validate the output file with a new | ||
cmd1 := exec.Command("diff", "testdata/JTY_output.yaml", "output.yaml") | ||
output, err = cmd1.CombinedOutput() | ||
if err != nil { | ||
t.Errorf("Error comparing output.yaml and testdata/test.yaml") | ||
} | ||
if string(output) != "" { | ||
t.Errorf("Expected output.yaml and testdata/test.yaml to be the same, but got error") | ||
} | ||
|
||
} |
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,37 @@ | ||
package test | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestKeyValueToJson(t *testing.T) { | ||
|
||
// it should convert a key-value file to json | ||
cmd := exec.Command("candy", "KVTJ", "-f", "testdata/env") | ||
|
||
// Capture the output | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Errorf("expected no error, but got: %v", err) | ||
} | ||
|
||
// Validate the cli output | ||
expecredOutput := "Operation completed successfully. Check the output.json file." | ||
got := strings.TrimSpace(string(output)) | ||
if got != expecredOutput { | ||
t.Errorf("expected %v, but got: %v", expecredOutput, got) | ||
} | ||
|
||
// Validate the output file with a new | ||
cmd1 := exec.Command("diff", "testdata/env_output.json", "output.json") | ||
output, err = cmd1.CombinedOutput() | ||
if err != nil { | ||
t.Errorf("Error comparing output.json and testdata/test.json") | ||
} | ||
if string(output) != "" { | ||
t.Errorf("Expected output.json and testdata/test.json to be the same, but got error") | ||
} | ||
|
||
} |
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,27 @@ | ||
package docker | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestKubernetesCmd(t *testing.T) { | ||
|
||
expectedOutput := "Kubernetes related commands." | ||
|
||
cmd := exec.Command("candy", "k8s") | ||
|
||
// Capture the output | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Errorf("expected no error, but got: %v", err) | ||
} | ||
|
||
// Validate the cli output | ||
got := strings.TrimSpace(string(output)[:28]) | ||
if got != expectedOutput { | ||
t.Errorf("expected %v, but got: %v", expectedOutput, got) | ||
} | ||
|
||
} |
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,25 @@ | ||
package test | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestRootCmd(t *testing.T) { | ||
|
||
expectedOutput := "Do all your tedious tasks with a single command" | ||
|
||
cmd := exec.Command("candy") | ||
|
||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Errorf("expected no error, but got: %v", err) | ||
} | ||
|
||
got := strings.TrimSpace(string(output)[:47]) | ||
if got != expectedOutput { | ||
t.Errorf("expected %v, but got: %v", expectedOutput, got) | ||
} | ||
|
||
} |
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,12 @@ | ||
{ | ||
"name": "JSON TO KEY TEST", | ||
"version": "1.0.0", | ||
"tag": [ | ||
"json", | ||
"key" | ||
], | ||
"properties": { | ||
"name": "test", | ||
"type": "string" | ||
} | ||
} |
Oops, something went wrong.