Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
DI-Tony-Reed committed Oct 9, 2024
0 parents commit 120d3d6
Show file tree
Hide file tree
Showing 14 changed files with 758 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tests.yaml
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 ./...
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tmp
coverage.html
bin
30 changes: 30 additions & 0 deletions Makefile
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
18 changes: 18 additions & 0 deletions README.md
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
```
37 changes: 37 additions & 0 deletions compare.go
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."
}
Loading

0 comments on commit 120d3d6

Please sign in to comment.