Skip to content

Commit

Permalink
chore: cleanup module dependencies and update CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wI2L committed Aug 27, 2021
1 parent 56b34ca commit 1d70c73
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 207 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ jobs:
fail-fast: false
matrix:
go:
- "1.14.x"
- "1.15.x"
- "1.16.x"
- "1.17.x"
os:
- ubuntu-latest
- macos-latest
Expand All @@ -44,7 +45,7 @@ jobs:
fail-fast: false
matrix:
go:
- "1.15.x"
- "1.17.x"
steps:
- name: Install Go
uses: actions/setup-go@v2
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ All notable changes to this project are documented in this file.

**THIS LIBRARY IS STILL IN ALPHA AND THERE ARE NO GUARANTEES REGARDING API STABILITY YET**

## [v0.1.1] - 2021-08-27
- Remove test dependency `k8s.io/api/core/v1` from modules list.
- Update the `go` versions used by the CI workflow's `test` and `bench` matrixes.

## [v0.1.0] - 2020-12-06
Initial release.

[v0.1.0]: https://github.com/wI2L/jsondiff/releases/tag/v0.1.0
[v0.1.1]: https://github.com/wI2L/jsondiff/releases/tag/v0.1.1
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,18 @@ The benchmark was run 10x (statistics computed with [benchstat](https://godoc.or
OS : macOS Catalina (10.15.7)
CPU: 1.4 GHz Intel Core i5
Mem: 16GB 2133 MHz
Go : go version go1.15.5 darwin/amd64
Tag: v0.1.0
Go : go version go1.17 darwin/amd64
Tag: v0.1.1
```

<details open><summary>Output</summary><br><pre>
name time/op
CompareJSONOpts/default-8 26.5µs ± 1%
CompareJSONOpts/invertible-8 27.4µs ± 1%
CompareJSONOpts/factorize-8 31.6µs ± 1%
CompareJSONOpts/rationalize-8 90.3µs ± 0%
CompareJSONOpts/factor+ratio-8 95.5µs ± 1%
CompareJSONOpts/all-options-8 126µs ± 1%
CompareJSONOpts/default-8 24.8µs ± 1%
CompareJSONOpts/invertible-8 25.6µs ± 0%
CompareJSONOpts/factorize-8 29.5µs ± 1%
CompareJSONOpts/rationalize-8 76.6µs ± 1%
CompareJSONOpts/factor+ratio-8 81.4µs ± 1%
CompareJSONOpts/all-options-8 106µs ± 1%
</pre></details>

## Credits
Expand Down
79 changes: 58 additions & 21 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,73 @@ import (
"log"

"github.com/wI2L/jsondiff"
corev1 "k8s.io/api/core/v1"
)

type (
Pod struct {
Spec PodSpec `json:"spec,omitempty"`
}
PodSpec struct {
Containers []Container `json:"containers,omitempty"`
Volumes []Volume `json:"volumes,omitempty"`
}
Container struct {
Name string `json:"name"`
Image string `json:"image,omitempty"`
VolumeMounts []VolumeMount `json:"volumeMounts,omitempty"`
}
Volume struct {
Name string `json:"name"`
VolumeSource `json:",inline"`
}
VolumeSource struct {
EmptyDir *EmptyDirVolumeSource `json:"emptyDir,omitempty"`
}
VolumeMount struct {
Name string `json:"name"`
MountPath string `json:"mountPath"`
}
EmptyDirVolumeSource struct {
Medium StorageMedium `json:"medium,omitempty"`
}
StorageMedium string
)

const (
StorageMediumDefault StorageMedium = ""
StorageMediumMemory StorageMedium = "Memory"
)

func ExampleCompare() {
pod := corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "webserver",
Image: "nginx:latest",
VolumeMounts: []corev1.VolumeMount{{
Name: "shared-data",
MountPath: "/usr/share/nginx/html",
createPod := func() Pod {
return Pod{
Spec: PodSpec{
Containers: []Container{{
Name: "webserver",
Image: "nginx:latest",
VolumeMounts: []VolumeMount{{
Name: "shared-data",
MountPath: "/usr/share/nginx/html",
}},
}},
}},
Volumes: []corev1.Volume{{
Name: "shared-data",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumMemory,
Volumes: []Volume{{
Name: "shared-data",
VolumeSource: VolumeSource{
EmptyDir: &EmptyDirVolumeSource{
Medium: StorageMediumMemory,
},
},
},
}},
},
}},
},
}
}
newPod := pod.DeepCopy()
oldPod := createPod()
newPod := createPod()

newPod.Spec.Containers[0].Image = "nginx:1.19.5-alpine"
newPod.Spec.Volumes[0].EmptyDir.Medium = corev1.StorageMediumDefault
newPod.Spec.Volumes[0].EmptyDir.Medium = StorageMediumDefault

patch, err := jsondiff.Compare(pod, newPod)
patch, err := jsondiff.Compare(oldPod, newPod)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/wI2L/jsondiff

go 1.15

require k8s.io/api v0.19.4
go 1.17
Loading

0 comments on commit 1d70c73

Please sign in to comment.