Skip to content
Open
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
44 changes: 44 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Integration tests

on:
push:
branches: &branches
- "master"
- "release/**"
paths-ignore: &paths-ignore
- ".github/**"
- ".run/**"
- ".vscode/**"
- "docs/**"
- "examples/**"
- "charts/**"
- "hack/**"
- "ui/static/**"
- "**/*.md"
- "**/*.gitignore"
- "**/*.gitattributes"
- "Makefile"
- ".golangci.yml"
pull_request:
branches: *branches
paths-ignore: *paths-ignore
workflow_dispatch:

jobs:
ci_job:
name: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true

- name: Run integration tests
run: make test-integ
shell: bash
2 changes: 1 addition & 1 deletion .run/markdown.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="markdown" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="relimpact" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="--old=a9697f4 --new=HEAD --format=markdown --greedy --output=tmp-report.md" />
<parameters value="--old=269945d --new=5a0c267 --format=markdown --greedy --output=tmp-report.md" />
<kind value="FILE" />
<package value="github.com/hashmap-kz/relimpact" />
<directory value="$PROJECT_DIR$" />
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ snapshot:
test-cov:
go test -coverprofile=$(COV_REPORT) ./...
go tool cover -html=$(COV_REPORT)

.PHONY: test-integ
test-integ: build
RELIMPACT_BIN=./bin/relimpact \
rm -rf test/integration/bin \
&& mv bin/ test/integration \
&& go test ./test/integration -tags=integration -v
44 changes: 44 additions & 0 deletions test/integration/exec_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//go:build integration

package integration

import (
"bytes"
"fmt"
"os/exec"
"strings"
)

// Without stdin
// out, err := runCmd("echo", "hello world")
// fmt.Printf("output: %q, err: %v\n", out, err)
func runCmd(name string, args ...string) (string, error) {
cmd := exec.Command(name, args...)

var out, stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
return "", fmt.Errorf("%w: %s", err, stderr.String())
}
return out.String(), nil
}

// With stdin
// out, err = runCmdWithStdin("hello from stdin\n", "cat")
// fmt.Printf("output: %q, err: %v\n", out, err)
func runCmdWithStdin(stdin string, name string, args ...string) (string, error) {
cmd := exec.Command(name, args...)

cmd.Stdin = strings.NewReader(stdin)

var out, stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
return "", fmt.Errorf("%w: %s", err, stderr.String())
}
return out.String(), nil
}
36 changes: 36 additions & 0 deletions test/integration/md_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//go:build integration

package integration

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func relimpactBin() string {
// TODO: also with envs
return "./bin/relimpact"
}

func relimpactRepoURL() string {
return "https://github.com/hashmap-kz/relimpact.git"
}

func TestExpected_Result1(t *testing.T) {
tmpDir := t.TempDir()

_, err := runCmd("git", "clone", relimpactRepoURL(), tmpDir)
require.NoError(t, err)

md, err := runCmd(relimpactBin(), "--old", "269945d", "--new", "5a0c267", "--greedy", "--dir", tmpDir)
require.NoError(t, err)

readFile, err := os.ReadFile(filepath.Join("testdata", t.Name()+".md"))
require.NoError(t, err)

expected := string(readFile)
require.Equal(t, expected, md)
}
Loading
Loading