osbase/jsonpatch: delete unused package
Change-Id: Idcf02e566f0f7c1ec0362d1e7ac1201bb1772294
Reviewed-on: https://review.monogon.dev/c/monogon/+/4039
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
Tested-by: Jenkins CI
diff --git a/osbase/jsonpatch/BUILD.bazel b/osbase/jsonpatch/BUILD.bazel
deleted file mode 100644
index dc3dd00..0000000
--- a/osbase/jsonpatch/BUILD.bazel
+++ /dev/null
@@ -1,14 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
-
-go_library(
- name = "jsonpatch",
- srcs = ["jsonpatch.go"],
- importpath = "source.monogon.dev/osbase/jsonpatch",
- visibility = ["//visibility:public"],
-)
-
-go_test(
- name = "jsonpatch_test",
- srcs = ["jsonpatch_test.go"],
- embed = [":jsonpatch"],
-)
diff --git a/osbase/jsonpatch/jsonpatch.go b/osbase/jsonpatch/jsonpatch.go
deleted file mode 100644
index 5f9c20d..0000000
--- a/osbase/jsonpatch/jsonpatch.go
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright The Monogon Project Authors.
-// SPDX-License-Identifier: Apache-2.0
-
-// Package jsonpatch contains data structures and encoders for JSON Patch (RFC
-// 6902) and JSON Pointers (RFC 6901)
-package jsonpatch
-
-import "strings"
-
-// JsonPatchOp describes a JSON Patch operation (RFC 6902 Section 4)
-type JsonPatchOp struct {
- Operation string `json:"op"`
- Path string `json:"path"` // Technically a JSON Pointer, but called Path in the RFC
- From string `json:"from,omitempty"`
- Value interface{} `json:"value,omitempty"`
-}
-
-// EncodeJSONRefToken encodes a JSON reference token as part of a JSON Pointer
-// (RFC 6901 Section 2)
-func EncodeJSONRefToken(token string) string {
- x := strings.ReplaceAll(token, "~", "~0")
- return strings.ReplaceAll(x, "/", "~1")
-}
-
-// PointerFromParts returns an encoded JSON Pointer from parts
-func PointerFromParts(pathParts []string) string {
- var encodedParts []string
- encodedParts = append(encodedParts, "")
- for _, part := range pathParts {
- encodedParts = append(encodedParts, EncodeJSONRefToken(part))
- }
- return strings.Join(encodedParts, "/")
-}
diff --git a/osbase/jsonpatch/jsonpatch_test.go b/osbase/jsonpatch/jsonpatch_test.go
deleted file mode 100644
index f41b030..0000000
--- a/osbase/jsonpatch/jsonpatch_test.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright The Monogon Project Authors.
-// SPDX-License-Identifier: Apache-2.0
-
-package jsonpatch
-
-import (
- "testing"
-)
-
-func TestEncodeJSONRefToken(t *testing.T) {
- tests := []struct {
- name string
- token string
- want string
- }{
- {"Passes through normal characters", "asdf123", "asdf123"},
- {"Encodes simple slashes", "a/b", "a~1b"},
- {"Encodes tildes", "m~n", "m~0n"},
- {"Encodes bot tildes and slashes", "a/m~n", "a~1m~0n"},
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- if got := EncodeJSONRefToken(tt.token); got != tt.want {
- t.Errorf("EncodeJSONRefToken() = %v, want %v", got, tt.want)
- }
- })
- }
-}
-
-func TestPointerFromParts(t *testing.T) {
- type args struct {
- pathParts []string
- }
- tests := []struct {
- name string
- args args
- want string
- }{
- {"Empty path", args{[]string{}}, ""},
- {"Single level path", args{[]string{"foo"}}, "/foo"},
- {"Multi-level path", args{[]string{"foo", "0"}}, "/foo/0"},
- {"Path starting with empty key", args{[]string{""}}, "/"},
- {"Path with part containing /", args{[]string{"a/b"}}, "/a~1b"},
- {"Path with part containing spaces", args{[]string{" "}}, "/ "},
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- if got := PointerFromParts(tt.args.pathParts); got != tt.want {
- t.Errorf("PointerFromParts() = %v, want %v", got, tt.want)
- }
- })
- }
-}