Update deps

This commit is contained in:
Frank Denis 2018-03-07 18:29:26 +01:00
parent 75f3c6403b
commit d8f502f130
7 changed files with 132 additions and 19 deletions

View file

@ -3,10 +3,9 @@ go_import_path: github.com/kardianos/service
sudo: required
go:
- 1.6.x
- 1.7.x
- 1.8.x
- 1.9.x
- "1.10"
- master
before_install:

View file

@ -8,6 +8,7 @@
package service_test
import (
"flag"
"fmt"
"io/ioutil"
"log"
@ -23,17 +24,18 @@ import (
const runAsServiceArg = "RunThisAsService"
func TestMain(m *testing.M) {
if len(os.Args) == 2 {
reportDir := flag.String("su.reportDir", "", "")
runAsService := flag.Bool("su.runAsService", false, "")
flag.Parse()
if !*runAsService {
os.Exit(m.Run())
} else if len(os.Args) == 4 && os.Args[2] == runAsServiceArg {
reportDir := os.Args[3]
writeReport(reportDir, "call")
runService()
writeReport(reportDir, "finished")
os.Exit(0)
}
log.Fatalf("Invalid arguments: %v", os.Args)
if len(*reportDir) == 0 {
log.Fatal("missing su.reportDir argument")
}
writeReport(*reportDir, "call")
runService()
writeReport(*reportDir, "finished")
}
func TestInstallRunRestartStopRemove(t *testing.T) {
@ -168,7 +170,7 @@ func mustNewRunAsService(
) service.Service {
sc := &service.Config{
Name: "go_service_test",
Arguments: []string{"-test.v=true", runAsServiceArg, reportDir},
Arguments: []string{"-test.v=true", "-su.runAsService", "-su.reportDir", reportDir},
}
s, err := service.New(p, sc)
if err != nil {

View file

@ -9,6 +9,8 @@ import (
"fmt"
"os"
"os/signal"
"regexp"
"strconv"
"text/template"
"time"
)
@ -54,6 +56,47 @@ func (s *upstart) configPath() (cp string, err error) {
cp = "/etc/init/" + s.Config.Name + ".conf"
return
}
func (s *upstart) hasKillStanza() bool {
defaultValue := true
out, err := exec.Command("/sbin/init", "--version").Output()
if err != nil {
return defaultValue
}
re := regexp.MustCompile(`init \(upstart (\d+.\d+.\d+)\)`)
matches := re.FindStringSubmatch(string(out))
if len(matches) != 2 {
return defaultValue
}
version := make([]int, 3)
for idx, vStr := range strings.Split(matches[1], ".") {
version[idx], err = strconv.Atoi(vStr)
if err != nil {
return defaultValue
}
}
maxVersion := []int{0, 6, 5}
if versionAtMost(version, maxVersion) {
return false
}
return defaultValue
}
func versionAtMost(version, max []int) bool {
for idx, m := range max {
v := version[idx]
if v > m {
return false
}
}
return true
}
func (s *upstart) template() *template.Template {
return template.Must(template.New("").Funcs(tf).Parse(upstartScript))
}
@ -81,10 +124,12 @@ func (s *upstart) Install() error {
var to = &struct {
*Config
Path string
Path string
HasKillStanza bool
}{
s.Config,
path,
s.hasKillStanza(),
}
return s.template().Execute(f, to)
@ -149,7 +194,7 @@ const upstartScript = `# {{.Description}}
{{if .DisplayName}}description "{{.DisplayName}}"{{end}}
kill signal INT
{{if .HasKillStanza}}kill signal INT{{end}}
{{if .ChRoot}}chroot {{.ChRoot}}{{end}}
{{if .WorkingDirectory}}chdir {{.WorkingDirectory}}{{end}}
start on filesystem or runlevel [2345]

View file

@ -41,6 +41,10 @@ var (
ErrMustRevalidateNoArgs = errors.New("Unexpected argument to `must-revalidate`")
ErrPublicNoArgs = errors.New("Unexpected argument to `public`")
ErrProxyRevalidateNoArgs = errors.New("Unexpected argument to `proxy-revalidate`")
// Experimental
ErrImmutableNoArgs = errors.New("Unexpected argument to `immutable`")
ErrStaleIfErrorDeltaSeconds = errors.New("Failed to parse delta-seconds in `stale-if-error`")
ErrStaleWhileRevalidateDeltaSeconds = errors.New("Failed to parse delta-seconds in `stale-while-revalidate`")
)
func whitespace(b byte) bool {
@ -403,6 +407,21 @@ type ResponseCacheDirectives struct {
// proxy-revalidate response directive.
SMaxAge DeltaSeconds
////
// Experimental features
// - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Extension_Cache-Control_directives
// - https://www.fastly.com/blog/stale-while-revalidate-stale-if-error-available-today
////
// immutable(cast-to-bool): experimental feature
Immutable bool
// stale-if-error(delta seconds): experimental feature
StaleIfError DeltaSeconds
// stale-while-revalidate(delta seconds): experimental feature
StaleWhileRevalidate DeltaSeconds
// Extensions: http://tools.ietf.org/html/rfc7234#section-5.2.3
//
// The Cache-Control header field can be extended through the use of one
@ -416,6 +435,9 @@ func ParseResponseCacheControl(value string) (*ResponseCacheDirectives, error) {
cd := &ResponseCacheDirectives{
MaxAge: -1,
SMaxAge: -1,
// Exerimantal stale timeouts
StaleIfError: -1,
StaleWhileRevalidate: -1,
}
err := parse(value, cd)
@ -446,6 +468,13 @@ func (cd *ResponseCacheDirectives) addToken(token string) error {
err = ErrMaxAgeDeltaSeconds
case "s-maxage":
err = ErrSMaxAgeDeltaSeconds
// Experimental
case "immutable":
cd.Immutable = true
case "stale-if-error":
err = ErrMaxAgeDeltaSeconds
case "stale-while-revalidate":
err = ErrMaxAgeDeltaSeconds
default:
cd.Extensions = append(cd.Extensions, token)
}
@ -500,6 +529,13 @@ func (cd *ResponseCacheDirectives) addPair(token string, v string) error {
cd.MaxAge, err = parseDeltaSeconds(v)
case "s-maxage":
cd.SMaxAge, err = parseDeltaSeconds(v)
// Experimental
case "immutable":
err = ErrImmutableNoArgs
case "stale-if-error":
cd.StaleIfError, err = parseDeltaSeconds(v)
case "stale-while-revalidate":
cd.StaleWhileRevalidate, err = parseDeltaSeconds(v)
default:
// TODO(pquerna): this sucks, making user re-parse, and its technically not 'quoted' like the original,
// but this is still easier, just a SplitN on "="

View file

@ -246,6 +246,27 @@ func TestResPrivate(t *testing.T) {
require.Equal(t, cd.PrivatePresent, true)
}
func TestResImmutable(t *testing.T) {
cd, err := ParseResponseCacheControl(`immutable`)
require.NoError(t, err)
require.NotNil(t, cd)
require.Equal(t, cd.Immutable, true)
}
func TestResStaleIfError(t *testing.T) {
cd, err := ParseResponseCacheControl(`stale-if-error=99999`)
require.NoError(t, err)
require.NotNil(t, cd)
require.Equal(t, cd.StaleIfError, DeltaSeconds(99999))
}
func TestResStaleWhileRevalidate(t *testing.T) {
cd, err := ParseResponseCacheControl(`stale-while-revalidate=99999`)
require.NoError(t, err)
require.NotNil(t, cd)
require.Equal(t, cd.StaleWhileRevalidate, DeltaSeconds(99999))
}
func TestParseDeltaSecondsZero(t *testing.T) {
ds, err := parseDeltaSeconds("0")
require.NoError(t, err)