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

Added unit tests. #61

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test
on: [push, pull_request]
jobs:
build:
name: Test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- uses: actions/checkout@v2

- name: Test
run: |
go get -d -v
go test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/*.txt
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Find and Replace Action

[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Find%20and%20Replace-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/jacobtomlinson/gha-find-replace)
[![Actions Status](https://github.com/jacobtomlinson/gha-find-replace/workflows/Build/badge.svg)](https://github.com/jacobtomlinson/gha-find-replace/actions)
[![Actions Status](https://github.com/jacobtomlinson/gha-find-replace/workflows/Integration%20Test/badge.svg)](https://github.com/jacobtomlinson/gha-find-replace/actions)
[![Build](https://github.com/jacobtomlinson/gha-find-replace/workflows/Build/badge.svg)](https://github.com/jacobtomlinson/gha-find-replace/actions)
[![Integration Tests](https://github.com/jacobtomlinson/gha-find-replace/workflows/Integration%20Test/badge.svg)](https://github.com/jacobtomlinson/gha-find-replace/actions)
[![Unit Tests](https://github.com/jacobtomlinson/gha-find-replace/actions/workflows/test.yml/badge.svg)](https://github.com/jacobtomlinson/gha-find-replace/actions/workflows/test.yml)

This action will find and replace strings in your project files.

Expand Down Expand Up @@ -159,6 +160,25 @@ _If you need the push event to trigger other workflows, use a `repo` scoped [Per
branch: ${{ github.ref }}
```

## Contributing

Install [go](https://go.dev/doc/install). This project currently uses Go 1.13. We recommend [gvm](https://github.com/moovweb/gvm) to switch between multiple go versions.

```
$ go version
go version go1.13 darwin/amd64
```

Build and test.

```
go get -d -v
go test
go build -v .
```

Make your code changes, add tests, and make a pull request!

## Publishing

To publish a new version of this Action we need to update the Docker image tag in `action.yml` and also create a new release on GitHub.
Expand Down
31 changes: 31 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"io/ioutil"
"os"
"testing"
)

func TestHappyPath(t *testing.T) {
if err := ioutil.WriteFile("out/data.txt", []byte("Hello world\n"), 0644); err != nil {
t.Error(err)
}

os.Setenv("INPUT_INCLUDE", "out/data.txt")
os.Setenv("INPUT_EXCLUDE", "")
os.Setenv("INPUT_FIND", "world")
os.Setenv("INPUT_REPLACE", "there")
os.Setenv("GITHUB_OUTPUT", "out/output.txt")

main()

data, err := ioutil.ReadFile("out/data.txt")
if err != nil {
t.Error(err)
}

want := "Hello there\n"
if string(data) != want {
t.Errorf("got %q, wanted %q", data, want)
}
}
1 change: 1 addition & 0 deletions out/.gitkeep
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of adding this to VCS maybe we could just dynamically create it in the test?

Copy link
Contributor Author

@dblock dblock Mar 11, 2024

Choose a reason for hiding this comment

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

That would mean including it in .gitignore to avoid others checking it in.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# placeholder