File tree 3 files changed +18
-11
lines changed
tests/KubeOps.Test/Operator/Webhook
3 files changed +18
-11
lines changed Original file line number Diff line number Diff line change 20
20
21
21
<ItemGroup >
22
22
<PackageReference Include =" CompareNETObjects" Version =" 4.79.0" />
23
- <PackageReference Include =" JsonDiffPatch" Version =" 2.0.61" />
24
23
<PackageReference Include =" Localtunnel" Version =" 1.0.5" />
25
24
<PackageReference Include =" McMaster.Extensions.CommandLineUtils" Version =" 4.0.2" />
26
25
<PackageReference Include =" McMaster.Extensions.Hosting.CommandLine" Version =" 4.0.2" />
29
28
<PackageReference Include =" prometheus-net.AspNetCore.HealthChecks" Version =" 7.0.0" />
30
29
<PackageReference Include =" SimpleBase" Version =" 4.0.0" />
31
30
<PackageReference Include =" System.Reactive" Version =" 5.0.0" />
31
+ <PackageReference Include =" SystemTextJson.JsonDiffPatch" Version =" 1.3.1" />
32
32
</ItemGroup >
33
33
34
34
<ItemGroup Condition =" '$(TargetFramework)' == 'net6.0'" >
Original file line number Diff line number Diff line change 1
- using JsonDiffPatch ;
1
+ using System . Text . Json . JsonDiffPatch ;
2
+ using System . Text . Json . JsonDiffPatch . Diffs . Formatters ;
3
+ using System . Text . Json . Nodes ;
2
4
using k8s ;
3
- using Newtonsoft . Json ;
4
- using Newtonsoft . Json . Linq ;
5
5
6
6
namespace KubeOps . Operator . Webhooks ;
7
7
8
8
internal static class KubernetesJsonDiffer
9
9
{
10
- private static readonly JsonDiffer JsonDiffer = new ( ) ;
10
+ private static readonly JsonPatchDeltaFormatter Formatter = new ( ) ;
11
11
12
- public static PatchDocument DiffObjects ( object ? from , object ? to )
12
+ public static JsonNode DiffObjects ( object ? from , object ? to )
13
13
{
14
14
var fromToken = GetJToken ( from ) ;
15
15
var toToken = GetJToken ( to ) ;
16
16
17
- return JsonDiffer . Diff ( fromToken , toToken , false ) ;
17
+ return fromToken . Diff ( toToken , Formatter ) ! ;
18
18
}
19
19
20
- private static JToken GetJToken ( object ? o )
20
+ private static JsonNode ? GetJToken ( object ? o )
21
21
{
22
22
// Use the K8s Serializer to ensure we match their naming conventions
23
23
// (and handle object conversions correctly).
24
24
var json = KubernetesJson . Serialize ( o ) ;
25
- return JToken . ReadFrom ( new JsonTextReader ( new StringReader ( json ) ) ) ;
25
+ return JsonNode . Parse ( json ) ;
26
26
}
27
27
}
Original file line number Diff line number Diff line change 1
1
using FluentAssertions ;
2
2
using k8s . Models ;
3
3
using KubeOps . Operator . Webhooks ;
4
- using Newtonsoft . Json ;
5
4
using Xunit ;
6
5
7
6
namespace KubeOps . Test . Operator . Webhook ;
@@ -17,8 +16,16 @@ public void When_diffing_objects_then_kubernetes_naming_conventions_should_be_us
17
16
var result = KubernetesJsonDiffer . DiffObjects ( left , right ) ;
18
17
19
18
// Should be all lowercase.
20
- result . ToString ( Formatting . None )
19
+ result . ToJsonString ( )
21
20
. Should ( )
22
21
. Be ( "[{\" op\" :\" replace\" ,\" path\" :\" /status/reason\" ,\" value\" :\" bar\" }]" ) ;
23
22
}
23
+
24
+ [ Fact ]
25
+ public void When_diffing_null_objects_then_no_errors_should_be_thrown ( )
26
+ {
27
+ var result = KubernetesJsonDiffer . DiffObjects ( null , null ) ;
28
+
29
+ Assert . NotNull ( result ) ;
30
+ }
24
31
}
You can’t perform that action at this time.
0 commit comments