-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from LerianStudio/test/MIDAZ-304
Test/MIDAZ-304
- Loading branch information
Showing
14 changed files
with
527 additions
and
14 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,36 @@ | ||
on: | ||
push: | ||
branches: | ||
- develop | ||
pull_request: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
integration-tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Docker Compose | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y docker-compose | ||
- name: Setup .env files | ||
run: make set-env | ||
|
||
- name: Start Docker Compose Services | ||
run: make up | ||
|
||
- name: Install CLI | ||
run: cd components/mdz && make install-local && cd - | ||
|
||
- name: Wait for services to be ready | ||
run: sleep 10 | ||
timeout-minutes: 2 | ||
|
||
- name: Run Integration Tests | ||
run: make test_integration_cli |
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
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,73 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Netflix/go-expect" | ||
"gotest.tools/golden" | ||
) | ||
|
||
func TestMDZLogin(t *testing.T) { | ||
cmd := exec.Command("mdz", "login", "--username", "user_john", "--password", "Lerian@123") | ||
|
||
var stdout, stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
|
||
if err := cmd.Run(); err != nil { | ||
t.Fatalf("Error executing command: %v\nStderr: %s", err, stderr.String()) | ||
} | ||
|
||
golden.AssertBytes(t, []byte(stdout.String()), "out_login_flags.golden") | ||
} | ||
|
||
func TestMDZLoginIt(t *testing.T) { | ||
console, err := expect.NewConsole(expect.WithStdout(os.Stdout)) | ||
if err != nil { | ||
t.Fatalf("Error creating console: %v", err) | ||
} | ||
defer console.Close() | ||
|
||
cmd := exec.Command("mdz", "login") | ||
cmd.Stdin = console.Tty() | ||
cmd.Stdout = console.Tty() | ||
cmd.Stderr = console.Tty() | ||
|
||
errChan := make(chan error, 1) | ||
|
||
go func() { | ||
if err := cmd.Start(); err != nil { | ||
errChan <- err | ||
return | ||
} | ||
|
||
if err := cmd.Wait(); err != nil { | ||
errChan <- err | ||
return | ||
} | ||
|
||
errChan <- nil | ||
}() | ||
|
||
time.Sleep(1 * time.Second) | ||
down(t, console) | ||
enter(t, console) | ||
sendInput(t, console, "user_john") | ||
sendInput(t, console, "Lerian@123") | ||
time.Sleep(1 * time.Second) | ||
|
||
if _, err := console.ExpectString("successfully logged in"); err != nil { | ||
t.Fatalf("Failed test: %v", err) | ||
} | ||
|
||
if err := <-errChan; err != nil { | ||
t.Fatalf("Command execution error: %v", err) | ||
} | ||
} |
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 @@ | ||
#!/bin/bash | ||
|
||
# Setting environment variables (if necessary) | ||
MDZ_CMD="mdz" | ||
USERNAME="user_john" | ||
PASSWORD="Lerian@123" | ||
LEGAL_NAME="Soul LLCT" | ||
DOING_BUSINESS_AS="The ledger.io" | ||
LEGAL_DOCUMENT="48784548000104" | ||
STATUS_CODE="ACTIVE" | ||
DESCRIPTION="Test Ledger" | ||
LINE1="Av Santso" | ||
LINE2="VJ 222" | ||
ZIP_CODE="04696040" | ||
CITY="West" | ||
STATE="VJ" | ||
COUNTRY="MG" | ||
METADATA='{"chave1": "valor1", "chave2": 2, "chave3": true}' | ||
|
||
# Function to execute commands and capture the output | ||
run_command() { | ||
echo "Executando: $1" | ||
OUTPUT=$($1) | ||
echo "$OUTPUT" | ||
} | ||
|
||
login_output=$(run_command "$MDZ_CMD login --username $USERNAME --password $PASSWORD") | ||
echo "$login_output" | ||
|
||
create_output=$(run_command "$MDZ_CMD organization create --legal-name $LEGAL_NAME --doing-business-as $DOING_BUSINESS_AS --legal-document $LEGAL_DOCUMENT --code $STATUS_CODE --description $DESCRIPTION --line1 $LINE1 --line2 $LINE2 --zip-code $ZIP_CODE --city $CITY --state $STATE --country $COUNTRY --metadata $METADATA") | ||
echo "$create_output" | ||
|
||
list_output=$(run_command "$MDZ_CMD organization list") | ||
echo "$list_output" | ||
|
||
ORG_ID=$(echo "$list_output" | grep -oP '[0-9a-fA-F-]{36}' | head -n 1) | ||
if [ -z "$ORG_ID" ]; then | ||
echo "Erro: No ID found!" | ||
exit 1 | ||
fi | ||
echo "organization id: $ORG_ID" | ||
|
||
describe_output=$(run_command "$MDZ_CMD organization describe --organization-id $ORG_ID") | ||
echo "$describe_output" | ||
|
||
update_output=$(run_command "$MDZ_CMD organization update --organization-id $ORG_ID --legal-name 'Updated Name' --doing-business-as 'Updated Business' --country 'BR'") | ||
echo "$update_output" | ||
|
||
echo "Test completed!" |
Oops, something went wrong.