-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
50 lines (44 loc) · 1.44 KB
/
Copy pathexample_test.go
File metadata and controls
50 lines (44 loc) · 1.44 KB
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
package example
import (
"os"
"path/filepath"
"testing"
"pocketmine-go/pocketmine/command"
"pocketmine-go/pocketmine/console"
"pocketmine-go/pocketmine/log"
"pocketmine-go/pocketmine/server"
)
func TestExamplePluginLoads(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "server.properties"), []byte("level-seed=1\n"), 0o644); err != nil {
t.Fatal(err)
}
s, err := server.New(dir, log.NewSimpleLogger())
if err != nil {
t.Fatal(err)
}
defer s.ForceShutdown()
p := s.GetPluginManager().GetPlugin("ExamplePlugin")
if p == nil || !p.IsEnabled() {
t.Fatal("ExamplePlugin wasn't loaded and enabled")
}
if _, err := os.Stat(filepath.Join(p.GetDataFolder(), "config.toml")); err != nil {
t.Errorf("the default config wasn't saved: %v", err)
}
if got := p.(*Main).GetConfig().Get("tip-interval", nil); got != 5 {
t.Errorf("tip-interval = %v (%T), want 5 from config.toml", got, got)
}
if p.(*Main).tipTask == nil {
t.Error("the tip task wasn't scheduled")
}
for _, name := range []string{"example", "ex", "exampleplugin:example"} {
cmd, ok := s.GetSimpleCommandMap().GetCommand(name).(command.PluginOwned)
if !ok || cmd.GetOwningPlugin() != p {
t.Errorf("/%s isn't the plugin's command", name)
}
}
sender := console.NewConsoleCommandSender(s, s.GetLanguage())
if !s.DispatchCommand(sender, "example", false) || !s.DispatchCommand(sender, "example reload", false) {
t.Error("/example didn't run")
}
}