TestJSONSerialization tests if the configuration structure can be serialized and then deserialized to/from JSON.
(t *testing.T)
| 50 | |
| 51 | // TestJSONSerialization tests if the configuration structure can be serialized and then deserialized to/from JSON. |
| 52 | func 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 | } |