Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-github-actions #12

Merged
merged 19 commits into from
Aug 31, 2023
Merged
38 changes: 38 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: tests
nabim777 marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54

- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.2.1

- name: Run bats test
working-directory: ./
run: |
bats tests/test_scan_command.bats
29 changes: 13 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
newPath string
}

func writeString(out io.Writer, msg string) error {
_, err := io.WriteString(out, msg)
if err != nil {
_, _ = io.WriteString(out, err.Error()) // Writing error message
return err
}
return nil
}

func getShifts(out io.Writer) int {
latestFeatures := getFeatures()

Expand Down Expand Up @@ -71,11 +80,9 @@
}
if found {
if o.LineNumber != l.LineNumber {
io.WriteString(out, "Found Shift\n")
io.WriteString(out, "Old: "+getTestPath(o))
io.WriteString(out, "\n")
io.WriteString(out, "New: "+getTestPath(l))
io.WriteString(out, "\n\n")
writeString(out, "Found Shift\n")

Check failure on line 83 in main.go

View workflow job for this annotation

GitHub Actions / build

Error return value is not checked (errcheck)
_, _ = io.WriteString(out, "New: "+getTestPath(l)+"\n")
_, _ = io.WriteString(out, "\n\n")

shifts = append(shifts, shift{getTestPath(o), getTestPath(l)})
}
Expand All @@ -84,9 +91,9 @@
}

if !found {
io.WriteString(out, "new scenario found\n")

Check failure on line 94 in main.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `io.WriteString` is not checked (errcheck)
io.WriteString(out, "New: "+getTestPath(l))

Check failure on line 95 in main.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `io.WriteString` is not checked (errcheck)
io.WriteString(out, "\n\n")

Check failure on line 96 in main.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `io.WriteString` is not checked (errcheck)
}
}

Expand Down Expand Up @@ -166,16 +173,6 @@
return 0
}

func deleteEmpty(s []string) []string {
var r []string
for _, str := range s {
if str != "" {
r = append(r, str)
}
}
return r
}

type update struct {
token string
linenumber int
Expand Down Expand Up @@ -260,11 +257,11 @@
exitStatus += scanForNewScenarios(out)
exitStatus += scanForRemovedScenarios(out)
default:
io.WriteString(out, "opps! seems like you forgot to provide the path of the feature file")
writeString(out, "opps! seems like you forgot to provide the path of the feature file")

Check failure on line 260 in main.go

View workflow job for this annotation

GitHub Actions / build

Error return value is not checked (errcheck)
exitStatus++
}
}
io.Copy(os.Stdout, out)

Check failure on line 264 in main.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `io.Copy` is not checked (errcheck)
os.Exit(exitStatus)
}

Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ go run main.go <command>
FEATURES_PATH=<path_to_feature_files> EXPECTED_FAILURES_DIR=<path_to_expected_failures> go run main.go shift
```

### Run test
- Install Bats (Bash Automated Testing System) on your system using the following command:
```bash
sudo apt install bats
```
- After installing Bats, you can run your tests locally using the following command:
nabim777 marked this conversation as resolved.
Show resolved Hide resolved
```bash
bats tests/test_scan_command.bats
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better to not hard-code the filename incase we add other tests as well?

Suggested change
bats tests/test_scan_command.bats
bats tests/<path-to-the-test-file>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be done this way?
bats tests/*.bats

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that will work and in the future a developer can run all the bats tests without needing to know what the filename(s) are.

phil@phil-Inspiron-5468:~/git/JankariTech/expected-failures-updater$ bats tests/*.bats
 ✓ detect removed scenarios
 ✓ detect new added scenarios

2 tests, 0 failures

phil-davis marked this conversation as resolved.
Show resolved Hide resolved
```
Loading