-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
43 lines (37 loc) · 971 Bytes
/
status.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
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package payload
import (
"fmt"
"sort"
"strings"
"github.com/juju/collections/set"
"github.com/juju/errors"
)
// The Juju-recognized states in which a payload might be.
const (
StateUndefined = ""
//TODO(wwitzel3) remove defined throughout
StateDefined = "defined"
StateStarting = "starting"
StateRunning = "running"
StateStopping = "stopping"
StateStopped = "stopped"
)
var okayStates = set.NewStrings(
StateStarting,
StateRunning,
StateStopping,
StateStopped,
)
// ValidateState verifies the state passed in is a valid okayState.
func ValidateState(state string) error {
if !okayStates.Contains(state) {
supported := okayStates.Values()
sort.Strings(supported)
states := strings.Join(supported, `", "`)
msg := fmt.Sprintf(`status %q not supported; expected one of ["%s"]`, state, states)
return errors.NewNotValid(nil, msg)
}
return nil
}