Skip to content

Commit

Permalink
Added unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Feb 4, 2024
1 parent 3a8ed85 commit 462aae1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
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
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)
}
}

0 comments on commit 462aae1

Please sign in to comment.