コード例 #1
0
ファイル: tools_test.go プロジェクト: kapilt/juju
func (s *toolsSuite) TestFindBootstrapTools(c *gc.C) {
	var called int
	var filter tools.Filter
	s.PatchValue(bootstrap.FindTools, func(_ environs.ConfigGetter, major, minor int, f tools.Filter, retry bool) (tools.List, error) {
		called++
		c.Check(major, gc.Equals, version.Current.Major)
		c.Check(minor, gc.Equals, version.Current.Minor)
		c.Check(retry, jc.IsFalse)
		filter = f
		return nil, nil
	})

	vers := version.MustParse("1.2.1")
	arm64 := "arm64"

	type test struct {
		version *version.Number
		arch    *string
		dev     bool
		filter  tools.Filter
	}
	tests := []test{{
		version: nil,
		arch:    nil,
		dev:     false,
		filter:  tools.Filter{Released: true},
	}, {
		version: nil,
		arch:    nil,
		dev:     true,
		filter:  tools.Filter{},
	}, {
		version: &vers,
		arch:    nil,
		dev:     false,
		filter:  tools.Filter{Number: vers},
	}, {
		version: nil,
		arch:    &arm64,
		dev:     false,
		filter:  tools.Filter{Arch: arm64, Released: true},
	}, {
		version: &vers,
		arch:    &arm64,
		dev:     true,
		filter:  tools.Filter{Arch: arm64, Number: vers},
	}}

	for i, test := range tests {
		c.Logf("test %d: %#v", i, test)
		bootstrap.FindBootstrapTools(nil, test.version, test.arch, test.dev)
		c.Assert(called, gc.Equals, i+1)
		c.Assert(filter, gc.Equals, test.filter)
	}
}
コード例 #2
0
ファイル: tools_test.go プロジェクト: pmatulis/juju
func (s *toolsSuite) TestFindBootstrapTools(c *gc.C) {
	var called int
	var filter tools.Filter
	var findStream string
	s.PatchValue(bootstrap.FindTools, func(_ environs.Environ, major, minor int, stream string, f tools.Filter) (tools.List, error) {
		called++
		c.Check(major, gc.Equals, version.Current.Major)
		c.Check(minor, gc.Equals, version.Current.Minor)
		findStream = stream
		filter = f
		return nil, nil
	})

	vers := version.MustParse("1.2.1")
	devVers := version.MustParse("1.2-beta1")
	arm64 := "arm64"

	type test struct {
		version *version.Number
		arch    *string
		series  *string
		dev     bool
		filter  tools.Filter
		stream  string
	}
	tests := []test{{
		version: nil,
		arch:    nil,
		series:  nil,
		dev:     true,
		filter:  tools.Filter{},
	}, {
		version: &vers,
		arch:    nil,
		series:  nil,
		dev:     false,
		filter:  tools.Filter{Number: vers},
	}, {
		version: &vers,
		arch:    &arm64,
		series:  nil,
		filter:  tools.Filter{Arch: arm64, Number: vers},
	}, {
		version: &vers,
		arch:    &arm64,
		series:  nil,
		dev:     true,
		filter:  tools.Filter{Arch: arm64, Number: vers},
	}, {
		version: &devVers,
		arch:    &arm64,
		series:  nil,
		filter:  tools.Filter{Arch: arm64, Number: devVers},
	}, {
		version: &devVers,
		arch:    &arm64,
		series:  nil,
		filter:  tools.Filter{Arch: arm64, Number: devVers},
		stream:  "devel",
	}}

	for i, test := range tests {
		c.Logf("test %d: %#v", i, test)
		extra := map[string]interface{}{"development": test.dev}
		if test.stream != "" {
			extra["agent-stream"] = test.stream
		}
		env := newEnviron("foo", useDefaultKeys, extra)
		bootstrap.FindBootstrapTools(env, test.version, test.arch, test.series)
		c.Assert(called, gc.Equals, i+1)
		c.Assert(filter, gc.Equals, test.filter)
		if test.stream != "" {
			c.Check(findStream, gc.Equals, test.stream)
		} else {
			if test.dev || test.version.IsDev() {
				c.Check(findStream, gc.Equals, "devel")
			} else {
				c.Check(findStream, gc.Equals, "released")
			}
		}
	}
}