This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
generated from ContainerSSH/library-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconformance_test.go
100 lines (89 loc) · 2.59 KB
/
conformance_test.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package docker_test
import (
"net"
"os"
"testing"
"github.com/containerssh/geoip"
"github.com/containerssh/log"
"github.com/containerssh/metrics"
"github.com/containerssh/sshserver"
"github.com/containerssh/structutils"
"gopkg.in/yaml.v3"
"github.com/containerssh/docker/v2"
)
func TestConformance(t *testing.T) {
var factories = map[string]func(logger log.Logger) (sshserver.NetworkConnectionHandler, error){
"dockerrun": func(logger log.Logger) (sshserver.NetworkConnectionHandler, error) {
//goland:noinspection GoDeprecation
config := docker.DockerRunConfig{}
structutils.Defaults(&config)
testFile, err := os.Open("testdata/config-0.3.yaml")
if err != nil {
return nil, err
}
unmarshaller := yaml.NewDecoder(testFile)
unmarshaller.KnownFields(true)
if err := unmarshaller.Decode(&config); err != nil {
return nil, err
}
return getDockerRun(config, logger)
},
"session": func(logger log.Logger) (sshserver.NetworkConnectionHandler, error) {
config := docker.Config{}
structutils.Defaults(&config)
config.Execution.Mode = docker.ExecutionModeSession
return getDocker(config, logger)
},
"connection": func(logger log.Logger) (sshserver.NetworkConnectionHandler, error) {
config := docker.Config{}
structutils.Defaults(&config)
config.Execution.Mode = docker.ExecutionModeConnection
return getDocker(config, logger)
},
}
sshserver.RunConformanceTests(t, factories)
}
func getDocker(config docker.Config, logger log.Logger) (sshserver.NetworkConnectionHandler, error) {
connectionID := sshserver.GenerateConnectionID()
geoipProvider, err := geoip.New(geoip.Config{
Provider: geoip.DummyProvider,
})
if err != nil {
return nil, err
}
collector := metrics.New(geoipProvider)
return docker.New(
net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 2222,
Zone: "",
},
connectionID,
config,
logger,
collector.MustCreateCounter("backend_requests", "", ""),
collector.MustCreateCounter("backend_failures", "", ""),
)
}
//goland:noinspection GoDeprecation
func getDockerRun(config docker.DockerRunConfig, logger log.Logger) (sshserver.NetworkConnectionHandler, error) {
geoipProvider, err := geoip.New(geoip.Config{
Provider: geoip.DummyProvider,
})
if err != nil {
return nil, err
}
collector := metrics.New(geoipProvider)
return docker.NewDockerRun(
net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 2222,
Zone: "",
},
sshserver.GenerateConnectionID(),
config,
logger,
collector.MustCreateCounter("backend_requests", "", ""),
collector.MustCreateCounter("backend_failures", "", ""),
)
}