-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 120d3d6
Showing
14 changed files
with
758 additions
and
0 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,30 @@ | ||
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22' | ||
|
||
- name: Install dependencies | ||
run: go get . | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
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,3 @@ | ||
tmp | ||
coverage.html | ||
bin |
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,30 @@ | ||
CONTAINER_NAME := jsonDiff | ||
|
||
up: | ||
docker compose up -d | ||
|
||
clean: | ||
docker compose down | ||
|
||
test: | ||
docker exec $(CONTAINER_NAME) sh -c 'go test ./...' | ||
|
||
test-coverage: | ||
docker exec $(CONTAINER_NAME) sh -c ' \ | ||
go test -coverprofile=coverage.out -coverpkg=./... ./... && \ | ||
go tool cover -func=coverage.out && \ | ||
go tool cover -html=coverage.out -o coverage.html' | ||
rm coverage.out | ||
|
||
go_build: | ||
docker exec $(CONTAINER_NAME) sh -c ' \ | ||
GOARCH=amd64 GOOS=linux go build -buildvcs=false -o bin/$(CONTAINER_NAME)-linux && \ | ||
GOARCH=amd64 GOOS=darwin go build -buildvcs=false -o bin/$(CONTAINER_NAME)-darwin && \ | ||
GOARCH=amd64 GOOS=windows go build -buildvcs=false -o bin/$(CONTAINER_NAME)-windows' | ||
|
||
ecr_build: | ||
GOARCH=amd64 GOOS=linux go build -buildvcs=false -o bin/$(CONTAINER_NAME)-linux | ||
|
||
build: up go_build clean | ||
tests: up test clean | ||
tests-coverage: up test-coverage clean |
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,18 @@ | ||
[![Tests](https://github.com/DI-Tony-Reed/JSONDiff/actions/workflows/tests.yaml/badge.svg)](https://github.com/DI-Tony-Reed/JSONDiff/actions/workflows/tests.yaml) | ||
|
||
# What is this | ||
This tool simply accepts two JSON files and returns the lines that are different between them. It utilizes https://github.com/go-test/deep for the comparison. | ||
|
||
# How do I use this? | ||
Locally, you can clone this repository, build it via the Makefile, and run it by feeding it two JSON files: | ||
```bash | ||
make build | ||
./bin/jsonDiff-darwin json1.json json2.json | ||
``` | ||
|
||
Make sure to use the appropriate binary for your OS. The above example is assuming you are on a Mac. | ||
|
||
# Viewing test coverage | ||
```bash | ||
make tests-coverage && open coverage.html | ||
``` |
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,37 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/go-test/deep" | ||
) | ||
|
||
type JSONDiff struct { | ||
File1 File | ||
File2 File | ||
} | ||
|
||
func (j JSONDiff) FindDifferences() string { | ||
if j.File1.Bytes == nil || j.File2.Bytes == nil { | ||
return "No bytes defined for File1 and/or File2." | ||
} | ||
|
||
if j.File1.Map == nil || j.File2.Map == nil { | ||
return "No map defined for File1 and/or File2." | ||
} | ||
|
||
if bytes.Equal(j.File1.Bytes, j.File2.Bytes) { | ||
return "No differences found." | ||
} | ||
|
||
if diff := deep.Equal(j.File1.Map, j.File2.Map); diff != nil { | ||
differences := "Differences found:" | ||
for _, d := range diff { | ||
differences += fmt.Sprintf("\n%v", d) | ||
} | ||
|
||
return differences | ||
} | ||
|
||
return "No differences found." | ||
} |
Oops, something went wrong.