Files

59 lines
1.2 KiB
Go
Raw Permalink Normal View History

2017-05-25 22:05:04 -07:00
package ssh_config_test
2017-05-24 22:10:17 -07:00
2017-05-25 22:05:04 -07:00
import (
"fmt"
2022-06-05 12:44:00 -07:00
"path/filepath"
2017-05-25 22:05:04 -07:00
"strings"
"github.com/kevinburke/ssh_config"
)
2017-05-24 22:10:17 -07:00
func ExampleHost_Matches() {
2017-05-25 22:05:04 -07:00
pat, _ := ssh_config.NewPattern("test.*.example.com")
host := &ssh_config.Host{Patterns: []*ssh_config.Pattern{pat}}
2017-05-24 22:10:17 -07:00
fmt.Println(host.Matches("test.stage.example.com"))
fmt.Println(host.Matches("othersubdomain.example.com"))
// Output:
// true
// false
}
2017-05-25 08:00:10 -07:00
func ExamplePattern() {
2017-05-25 22:05:04 -07:00
pat, _ := ssh_config.NewPattern("*")
host := &ssh_config.Host{Patterns: []*ssh_config.Pattern{pat}}
2017-05-25 08:00:10 -07:00
fmt.Println(host.Matches("test.stage.example.com"))
fmt.Println(host.Matches("othersubdomain.any.any"))
// Output:
// true
// true
}
2017-05-25 22:05:04 -07:00
func ExampleDecode() {
var config = `
Host *.example.com
Compression yes
`
cfg, _ := ssh_config.Decode(strings.NewReader(config))
val, _ := cfg.Get("test.example.com", "Compression")
fmt.Println(val)
// Output: yes
}
2017-05-26 11:07:48 -07:00
func ExampleDefault() {
fmt.Println(ssh_config.Default("Port"))
fmt.Println(ssh_config.Default("UnknownVar"))
// Output:
// 22
//
}
2022-06-05 12:44:00 -07:00
func ExampleUserSettings_ConfigFinder() {
// This can be used to test SSH config parsing.
u := ssh_config.UserSettings{}
u.ConfigFinder(func() string {
return filepath.Join("testdata", "test_config")
})
u.Get("example.com", "Host")
}