forked from mtusi2026/mtusi2026lab2
29 lines
604 B
Go
29 lines
604 B
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRunRequiresAddress(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
host string
|
|
port string
|
|
want string
|
|
}{
|
|
{name: "missing host", port: "8080", want: "APP_HOST is required"},
|
|
{name: "missing port", host: "127.0.0.1", want: "APP_PORT is required"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Setenv("APP_HOST", tt.host)
|
|
t.Setenv("APP_PORT", tt.port)
|
|
if err := run(nil); err == nil || !strings.Contains(err.Error(), tt.want) {
|
|
t.Fatalf("run() error = %v, want %q", err, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|