-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellport_test.go
More file actions
71 lines (60 loc) · 1.86 KB
/
Copy pathshellport_test.go
File metadata and controls
71 lines (60 loc) · 1.86 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (C) 2019-2026 Ni Rui <ranqus@gmail.com>
// Copyright (C) 2026 Snuffy2
// SPDX-License-Identifier: AGPL-3.0-only
package main
import (
"path/filepath"
"testing"
"github.com/Snuffy2/shellport/application/configuration"
"github.com/Snuffy2/shellport/application/log"
)
func TestShouldPrintVersionAcceptsVersionFlags(t *testing.T) {
for _, args := range [][]string{
{"shellport", "-V"},
{"shellport", "--version"},
} {
if !shouldPrintVersion(args) {
t.Fatalf("shouldPrintVersion(%v) = false, want true", args)
}
}
}
func TestShouldPrintVersionRejectsOtherArgs(t *testing.T) {
for _, args := range [][]string{
{"shellport"},
{"shellport", "--help"},
{"shellport", "--version", "--help"},
} {
if shouldPrintVersion(args) {
t.Fatalf("shouldPrintVersion(%v) = true, want false", args)
}
}
}
func TestDebugLoggingEnabledFromEnvironmentValue(t *testing.T) {
t.Setenv("SHELLPORT_DEBUG", "1")
if !debugLoggingEnabled() {
t.Fatal("expected SHELLPORT_DEBUG to enable debug logging")
}
}
func TestDebugLoggingDisabledWhenEnvironmentEmpty(t *testing.T) {
t.Setenv("SHELLPORT_DEBUG", "")
if debugLoggingEnabled() {
t.Fatal("expected empty SHELLPORT_DEBUG to disable debug logging")
}
}
func TestConfigLoadersCreateConfiguredMissingFile(t *testing.T) {
configPath := filepath.Join(t.TempDir(), "custom-shellport.conf.yml")
t.Setenv("SHELLPORT_CONFIG", configPath)
_, cfg, err := configuration.Redundant(configLoaders()...)(log.NewDitch())
if err != nil {
t.Fatalf("config loader returned error: %v", err)
}
if cfg.SourceFile != configPath {
t.Fatalf("SourceFile = %q, want %q", cfg.SourceFile, configPath)
}
if len(cfg.Servers) == 0 {
t.Fatal("expected at least one default server in generated config")
}
if cfg.Servers[0].ListenInterface != "0.0.0.0" {
t.Fatalf("ListenInterface = %q, want 0.0.0.0", cfg.Servers[0].ListenInterface)
}
}