/
ShapelessDatastoreExampleTest.scala
52 lines (45 loc) · 1.84 KB
/
ShapelessDatastoreExampleTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright 2017 Spotify AB.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.spotify.scio.examples.extra
import com.google.datastore.v1.{Entity, Query}
import com.google.datastore.v1.client.DatastoreHelper.makeValue
import com.spotify.scio.testing._
class ShapelessDatastoreExampleTest extends PipelineSpec {
val textIn = Seq("a b c d e", "a b a b")
val wordCount = Seq(("a", 3L), ("b", 3L), ("c", 1L), ("d", 1L), ("e", 1L))
val entities = wordCount.map { kv =>
Entity.newBuilder()
.putProperties("word", makeValue(kv._1).build())
.putProperties("count", makeValue(kv._2).build())
.build()
}
val textOut = wordCount.map(kv => kv._1 + ": " + kv._2)
"ShapelessDatastoreWriteExample" should "work" in {
JobTest[com.spotify.scio.examples.extra.ShapelessDatastoreWriteExample.type]
.args("--input=in.txt", "--output=project")
.input(TextIO("in.txt"), textIn)
.output(DatastoreIO("project"))(_ should containInAnyOrder (entities))
.run()
}
"ShapelessDatastoreReadExample" should "work" in {
JobTest[com.spotify.scio.examples.extra.ShapelessDatastoreReadExample.type]
.args("--input=project", "--output=out.txt")
.input(DatastoreIO("project", Query.getDefaultInstance), entities)
.output(TextIO("out.txt"))(_ should containInAnyOrder (textOut))
.run()
}
}