mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
// Copyright 2015 Light Code Labs, LLC
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package startupshutdown
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mholt/caddy"
|
|
)
|
|
|
|
func TestStartup(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
shouldErr bool
|
|
}{
|
|
{name: "noInput", input: "startup", shouldErr: true},
|
|
{name: "startup", input: "startup cmd arg", shouldErr: false},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
c := caddy.NewTestController("", test.input)
|
|
|
|
err := Startup(c)
|
|
if err == nil && test.shouldErr {
|
|
t.Error("Test didn't error, but it should have")
|
|
} else if err != nil && !test.shouldErr {
|
|
t.Errorf("Test errored, but it shouldn't have; got '%v'", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestShutdown(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
shouldErr bool
|
|
}{
|
|
{name: "noInput", input: "shutdown", shouldErr: true},
|
|
{name: "shutdown", input: "shutdown cmd arg", shouldErr: false},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
c := caddy.NewTestController("", test.input)
|
|
|
|
err := Shutdown(c)
|
|
if err == nil && test.shouldErr {
|
|
t.Error("Test didn't error, but it should have")
|
|
} else if err != nil && !test.shouldErr {
|
|
t.Errorf("Test errored, but it shouldn't have; got '%v'", err)
|
|
}
|
|
})
|
|
}
|
|
}
|