(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func TestJSON6902(t *testing.T) { |
| 62 | t.Parallel() |
| 63 | |
| 64 | if actual := NewJSONPatch().Type(); actual != types.JSONPatchType { |
| 65 | t.Fatalf("expected %q, got %q", types.JSONPatchType, actual) |
| 66 | } |
| 67 | |
| 68 | // An empty patch is valid. |
| 69 | { |
| 70 | patch := NewJSONPatch() |
| 71 | if !patch.IsEmpty() { |
| 72 | t.Fatal("expected empty") |
| 73 | } |
| 74 | b, err := patch.Bytes() |
| 75 | if err != nil { |
| 76 | t.Fatalf("expected no error, got %v", err) |
| 77 | } |
| 78 | assertJSON(t, `[]`, b) |
| 79 | } |
| 80 | |
| 81 | // Calling Add without its value is an error. |
| 82 | { |
| 83 | patch := NewJSONPatch() |
| 84 | patch.Add("a") |
| 85 | _, err := patch.Bytes() |
| 86 | if err == nil { |
| 87 | t.Fatal("expected an error, got none") |
| 88 | } |
| 89 | } |
| 90 | { |
| 91 | b, err := NewJSONPatch().Add("a", "x/y", "0")(9).Bytes() |
| 92 | if err != nil { |
| 93 | t.Fatalf("expected no error, got %v", err) |
| 94 | } |
| 95 | assertJSON(t, `[{"op":"add","path":"/a/x~1y/0","value":9}]`, b) |
| 96 | } |
| 97 | |
| 98 | // Remove takes no value. |
| 99 | { |
| 100 | b, err := NewJSONPatch().Remove("b", "m/n/o").Bytes() |
| 101 | if err != nil { |
| 102 | t.Fatalf("expected no error, got %v", err) |
| 103 | } |
| 104 | assertJSON(t, `[{"op":"remove","path":"/b/m~1n~1o"}]`, b) |
| 105 | } |
| 106 | |
| 107 | // Calling Replace without its value is an error. |
| 108 | { |
| 109 | patch := NewJSONPatch() |
| 110 | patch.Replace("a") |
| 111 | _, err := patch.Bytes() |
| 112 | if err == nil { |
| 113 | t.Fatal("expected an error, got none") |
| 114 | } |
| 115 | } |
| 116 | { |
| 117 | b, err := NewJSONPatch().Replace("metadata", "labels", "some/thing")("5").Bytes() |
| 118 | if err != nil { |
nothing calls this directly
no test coverage detected