2019-06-18 16:47:29 +00:00
|
|
|
package updater
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-02-28 23:24:38 +00:00
|
|
|
"flag"
|
2019-06-18 16:47:29 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/facebookgo/grace/gracenet"
|
2020-11-25 06:55:13 +00:00
|
|
|
"github.com/rs/zerolog"
|
2019-06-18 16:47:29 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-02-28 23:24:38 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2024-09-11 23:00:00 +00:00
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
|
2019-06-18 16:47:29 +00:00
|
|
|
)
|
|
|
|
|
2024-09-11 23:00:00 +00:00
|
|
|
func init() {
|
|
|
|
Init(cliutil.GetBuildInfo("TEST", "TEST"))
|
|
|
|
}
|
|
|
|
|
2019-06-18 16:47:29 +00:00
|
|
|
func TestDisabledAutoUpdater(t *testing.T) {
|
|
|
|
listeners := &gracenet.Net{}
|
2020-11-25 06:55:13 +00:00
|
|
|
log := zerolog.Nop()
|
2021-02-28 23:24:38 +00:00
|
|
|
autoupdater := NewAutoUpdater(false, 0, listeners, &log)
|
2019-06-18 16:47:29 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
errC := make(chan error)
|
|
|
|
go func() {
|
|
|
|
errC <- autoupdater.Run(ctx)
|
|
|
|
}()
|
|
|
|
|
|
|
|
assert.False(t, autoupdater.configurable.enabled)
|
|
|
|
assert.Equal(t, DefaultCheckUpdateFreq, autoupdater.configurable.freq)
|
|
|
|
|
|
|
|
cancel()
|
|
|
|
// Make sure that autoupdater terminates after canceling the context
|
|
|
|
assert.Equal(t, context.Canceled, <-errC)
|
|
|
|
}
|
2021-02-28 23:24:38 +00:00
|
|
|
|
|
|
|
func TestCheckInWithUpdater(t *testing.T) {
|
|
|
|
flagSet := flag.NewFlagSet(t.Name(), flag.PanicOnError)
|
|
|
|
cliCtx := cli.NewContext(cli.NewApp(), flagSet, nil)
|
|
|
|
|
|
|
|
warningChecker := StartWarningCheck(cliCtx)
|
|
|
|
warning := warningChecker.getWarning()
|
|
|
|
// Assuming this runs either on a release or development version, then the Worker will never have anything to tell us.
|
|
|
|
assert.Empty(t, warning)
|
|
|
|
}
|