MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / TestJSONSerialization

Function TestJSONSerialization

internal/config/docker_test.go:52–84  ·  view source on GitHub ↗

TestJSONSerialization tests if the configuration structure can be serialized and then deserialized to/from JSON.

(t *testing.T)

Source from the content-addressed store, hash-verified

50
51// TestJSONSerialization tests if the configuration structure can be serialized and then deserialized to/from JSON.
52func TestJSONSerialization(t *testing.T) {
53 //t.Parallel()()
54
55 // region Setup
56 cfg := &config.DockerConfig{}
57 newCfg := &config.DockerConfig{}
58 structutils.Defaults(cfg)
59
60 buf := &bytes.Buffer{}
61 // endregion
62
63 // region Save
64 jsonEncoder := json.NewEncoder(buf)
65 assert.NoError(t, jsonEncoder.Encode(cfg))
66 // endregion
67
68 // region Load
69 jsonDecoder := json.NewDecoder(buf)
70 jsonDecoder.DisallowUnknownFields()
71 assert.NoError(t, jsonDecoder.Decode(newCfg))
72 // endregion
73
74 // region Assert
75
76 diff := cmp.Diff(
77 cfg,
78 newCfg,
79 cmp.AllowUnexported(config.DockerExecutionConfig{}),
80 cmpopts.EquateEmpty(),
81 )
82 assert.Empty(t, diff)
83 // endregion
84}

Callers

nothing calls this directly

Calls 3

EncodeMethod · 0.95
DecodeMethod · 0.95
DefaultsFunction · 0.92

Tested by

no test coverage detected