on master help sign in
Merge pull request #49 from DaQuirm/fix/envvar-json-encoding
ea7f6b0Deni Bertovic
src/Docker/Client/Types.hs+1−1
@@ -1348,7 +1348,7 @@ instance FromJSON EnvVar where
1348 parseJSON _ = fail "EnvVar is not a string"
1348 parseJSON _ = fail "EnvVar is not a string"
1349
1349
1350instance ToJSON EnvVar where
1350instance ToJSON EnvVar where
1351− toJSON (EnvVar n v) = object [n .= v]
1351+ toJSON (EnvVar n v) = JSON.String $ n <> T.pack "=" <> v
1352
1352
1353-- | ExposedPort represents a port (and it's type)
1353-- | ExposedPort represents a port (and it's type)
1354-- that a container should expose to other containers or the host system.
1354-- 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
163 Just (Entrypoint sampleEntrypointArr)
163 Just (Entrypoint sampleEntrypointArr)
164 sampleEntrypointArr = ["cmd", "--some-flag", "--some-flag2"]
164 sampleEntrypointArr = ["cmd", "--some-flag", "--some-flag2"]
165
165
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+
166integrationTests :: TestTree
175integrationTests :: TestTree
167integrationTests =
176integrationTests =
168 testGroup
177 testGroup
@@ -183,6 +192,7 @@ jsonTests =
183 , testLabelsJson
192 , testLabelsJson
184 , testLogDriverOptionsJson
193 , testLogDriverOptionsJson
185 , testEntrypointJson
194 , testEntrypointJson
195+ , testEnvVarJson
186 ]
196 ]
187
197
188setup :: IO ()
198setup :: IO ()