on master help sign in
Merge pull request #49 from DaQuirm/fix/envvar-json-encoding

Fix EnvVar JSON encoding

commitea7f6b0d5be320c388fcb930c5e7aa508725fe57 authorDeni Bertovic <deni@denibertovic.com> dateMon 8 Jan 2018, 15:09 (9 years ago) parent966b66d28ccd69
2 files changed+11−1
src/Docker/Client/Types.hs+1−1 tests/tests.hs+10
src/Docker/Client/Types.hs+1−1
@@ -1348,7 +1348,7 @@ instance FromJSON EnvVar where
13481348 parseJSON _ = fail "EnvVar is not a string"
13491349
13501350instance ToJSON EnvVar where
1351− toJSON (EnvVar n v) = object [n .= v]
1351+ toJSON (EnvVar n v) = JSON.String $ n <> T.pack "=" <> v
13521352
13531353-- | ExposedPort represents a port (and it's type)
13541354-- that a container should expose to other containers or the host system.
tests/tests.hs+10
@@ -163,6 +163,15 @@ testEntrypointJson = testGroup "Testing ContainerConfig JSON" [testSample1, test
163163 Just (Entrypoint sampleEntrypointArr)
164164 sampleEntrypointArr = ["cmd", "--some-flag", "--some-flag2"]
165165
166+testEnvVarJson :: TestTree
167+testEnvVarJson = testGroup "Testing EnvVar JSON" [testSampleEncode, testSampleDecode]
168+ where
169+ testSampleEncode =
170+ testCase "Test toJSON" $ assert $ JSON.toJSON (EnvVar "cellar" "door") == JSON.String "cellar=door"
171+ testSampleDecode =
172+ testCase "Test fromJSON" $ assert $ (JSON.decode "\"cellar=door\"" :: Maybe EnvVar) ==
173+ Just (EnvVar "cellar" "door")
174+
166175integrationTests :: TestTree
167176integrationTests =
168177 testGroup
@@ -183,6 +192,7 @@ jsonTests =
183192 , testLabelsJson
184193 , testLogDriverOptionsJson
185194 , testEntrypointJson
195+ , testEnvVarJson
186196 ]
187197
188198setup :: IO ()