Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit a8ff054

Browse files
author
Jonas
committed
Add test for file connector
1 parent 596f467 commit a8ff054

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

testall/src/main/scala/org/codeoverflow/plugins/testall/test.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ package org.codeoverflow.plugins.testall
22

33
import org.codeoverflow.chatoverflow.api.plugin.configuration.Requirement
44

5+
/**
6+
* Used for testing a connector.
7+
*
8+
* Pass all requirements required for this test and implement your tests in the `setup()`, `loop()` and `shutdown()` functions.
9+
* Also make sure to add the test in the `testallPlugin` class.
10+
*
11+
* @param plugin the testallPlugins instance (required for logging)
12+
* @param requirements the requirements that are used by this test
13+
*/
514
abstract class test(private val plugin: testallPlugin, val requirements : Requirement[_]*) {
615

716
/**
@@ -42,6 +51,6 @@ abstract class test(private val plugin: testallPlugin, val requirements : Requir
4251
*
4352
* @param message the message to show
4453
*/
45-
protected final def log(message: String): Unit = plugin.getManager.log(message)
54+
protected final def log(message: String): Unit = plugin.getManager.log(s"[$name] $message")
4655

4756
}

testall/src/main/scala/org/codeoverflow/plugins/testall/testallPlugin.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.codeoverflow.plugins.testall
22

33
import org.codeoverflow.chatoverflow.api.plugin.{PluginImpl, PluginManager}
4-
import org.codeoverflow.plugins.testall.tests.discordtest
4+
import org.codeoverflow.plugins.testall.tests.{discordtest, filetest}
55

66

77
class testallPlugin(manager: PluginManager) extends PluginImpl(manager) {
@@ -11,7 +11,12 @@ class testallPlugin(manager: PluginManager) extends PluginImpl(manager) {
1111
require.input.discordChat("reqDiscordIn", "Discord input", true),
1212
require.output.discordChat("reqDiscordOut", "Discord output", true),
1313
require.parameter.string("reqDiscordChannel", "The id of the channel to which the bot should connect", true)
14+
),
15+
new filetest(this,
16+
require.input.file("fileIn", "File input", true),
17+
require.output.file("fileOut", "File output", true)
1418
)
19+
//Add more tests here!
1520
)
1621

1722
private var running = Seq[test]()

testall/src/main/scala/org/codeoverflow/plugins/testall/tests/discordtest.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import org.codeoverflow.plugins.testall.{test, testallPlugin}
1111

1212
import scala.collection.JavaConverters._
1313

14+
/**
15+
* Test for the discord service, logs edited and deleted messages, tests sending of messages, embeds and files,
16+
* allows listing the recent messages with /message command
17+
*/
1418
class discordtest(val plugin: testallPlugin,
1519
val in: Requirement[DiscordChatInput],
1620
val out: Requirement[DiscordChatOutput],
@@ -34,7 +38,7 @@ class discordtest(val plugin: testallPlugin,
3438
.withDescription("test")
3539
.withAuthor("skateShiny", null, "https://cdn.discordapp.com/emojis/496389587329875981.png?v=1")
3640
.build())
37-
log(s"$name started successfully")
41+
log("Started successfully")
3842
}
3943

4044
def onMessage(message: DiscordChatMessage): Unit = {
@@ -49,14 +53,14 @@ class discordtest(val plugin: testallPlugin,
4953

5054

5155
def onMessageEdit(oldMessage: DiscordChatMessage, newMessage: DiscordChatMessage): Unit = {
52-
log(s"$name: Message #${oldMessage.getId} was edited from '$oldMessage' to '$newMessage'")
56+
log("Message #${oldMessage.getId} was edited from '$oldMessage' to '$newMessage'")
5357
}
5458

5559
def onMessageDelete(message: DiscordChatMessage): Unit = {
56-
log(s"$name: Message #${message.getId} was deleted (content: $message)")
60+
log("Message #${message.getId} was deleted (content: $message)")
5761
}
5862

5963
override def loop(): Unit = {}
6064

61-
override def shutdown(): Unit = log(s"Stopped $name")
65+
override def shutdown(): Unit = log("Stopped")
6266
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.codeoverflow.plugins.testall.tests
2+
3+
import org.codeoverflow.chatoverflow.api.io.input.FileInput
4+
import org.codeoverflow.chatoverflow.api.io.output.FileOutput
5+
import org.codeoverflow.chatoverflow.api.plugin.configuration.Requirement
6+
import org.codeoverflow.plugins.testall.{test, testallPlugin}
7+
8+
/**
9+
* Test the various different file system actions provided by FileInput and FileOutput
10+
*/
11+
class filetest(val plugin: testallPlugin, val in: Requirement[FileInput], val out: Requirement[FileOutput]) extends test(plugin, in, out) {
12+
13+
override def name: String = "Filesystem test"
14+
15+
override def setup(): Unit = {
16+
log("Testing creation of folder")
17+
log(out.get.createDirectory("test").toString)
18+
19+
log("Testing creation of folder #2")
20+
log(out.get.createDirectory("test2/test2").toString)
21+
22+
log("Testing creation of folder #3")
23+
log(out.get.createDirectory("ich/bin/ein/folder").toString)
24+
25+
log("Tesitng if file exists")
26+
log(out.get.exists("test.json").toString)
27+
28+
log("Tesitng if file exists (non existant)")
29+
log(out.get.exists("test2.json").toString)
30+
31+
32+
log("Test file reading:")
33+
val file = in.get.getFile("test.json")
34+
log(if (file.isPresent) file.get() else "false")
35+
36+
log("Test file writing:")
37+
log(out.get.saveFile(
38+
"""{
39+
| "type": "test",
40+
| "result": "success"
41+
|}
42+
""".stripMargin, "out.json").toString)
43+
44+
log("Tesitng if folder exists")
45+
log(out.get.exists("test/").toString)
46+
log(out.get.exists("test").toString)
47+
48+
log("Testing deletion of a folder")
49+
log(out.get.delete("test").toString)
50+
log(out.get.delete("test2/test2").toString)
51+
log(out.get.delete("ich/bin/ein/folder").toString)
52+
53+
log("Testing deletion of a file")
54+
log(out.get.delete("out.json").toString)
55+
}
56+
57+
override def loop(): Unit = {}
58+
59+
override def shutdown(): Unit = {}
60+
}

0 commit comments

Comments
 (0)