Example #1
0
func TestGetRunningDeploymentSet_otherCluster(t *testing.T) {
	//sous.Log.Vomit.SetFlags(sous.Log.Vomit.Flags() | log.Ltime)
	//sous.Log.Vomit.SetOutput(os.Stderr)
	//sous.Log.Vomit.Print("Starting stderr output")
	sous.Log.Debug.SetFlags(sous.Log.Debug.Flags() | log.Ltime)
	sous.Log.Debug.SetOutput(os.Stderr)
	sous.Log.Debug.Print("Starting stderr output")
	assert := assert.New(t)

	registerLabelledContainers()
	drc := docker_registry.NewClient()
	drc.BecomeFoolishlyTrusting()
	nc := docker.NewNameCache("", drc, newInMemoryDB("grds"))
	client := singularity.NewRectiAgent()
	d := singularity.NewDeployer(client)

	clusters := []string{"other-cluster"}

	ds, which := deploymentWithRepo(clusters, nc, assert, d, "github.com/opentable/docker-grafana")
	deps := ds.Snapshot()
	if assert.Equal(1, len(deps)) {
		grafana := deps[which]
		assert.Equal(SingularityURL, grafana.Cluster.BaseURL)
		assert.Regexp("^0\\.1", grafana.Resources["cpus"])    // XXX strings and floats...
		assert.Regexp("^100\\.", grafana.Resources["memory"]) // XXX strings and floats...
		assert.Equal("1", grafana.Resources["ports"])         // XXX strings and floats...
		assert.Equal(17, grafana.SourceID.Version.Patch)
		assert.Equal("91495f1b1630084e301241100ecf2e775f6b672c", grafana.SourceID.Version.Meta)
		assert.Equal(1, grafana.NumInstances)
		assert.Equal(sous.ManifestKindService, grafana.Kind)
	}

	ResetSingularity()
}
Example #2
0
func TestModifyResources(t *testing.T) {
	assert := assert.New(t)
	version := "1.2.3-test"

	pair := baseDeployablePair()

	pair.Prior.Deployment.SourceID.Version = semv.MustParse(version)
	pair.Prior.Deployment.Resources["memory"] = "100"

	pair.Post.Deployment.SourceID.Version = semv.MustParse(version)
	pair.Post.Deployment.Resources["memory"] = "500"
	pair.Post.BuildArtifact.Name = "1.2.3"

	mods := make(chan *sous.DeployablePair, 1)
	errs := make(chan error, 10)

	client := sous.NewDummyRectificationClient()
	deployer := NewDeployer(client)

	mods <- pair
	close(mods)
	deployer.RectifyModifies(mods, errs)
	close(errs)

	for e := range errs {
		t.Error(e)
	}

	assert.Len(client.Created, 0)

	if assert.Len(client.Deployed, 1) {
		assert.Regexp("1.2.3", client.Deployed[0].ImageName)
		assert.Regexp("500", client.Deployed[0].Res["memory"])
	}
}
Example #3
0
func TestMetadataGetAll(t *testing.T) {
	output := runCommand(t, []string{}, config.DeployFilterFlags{
		Repo: project1.Repo,
	})

	assert.Regexp(t, "BuildBranch", output)
	assert.Regexp(t, "master", output)
	assert.Regexp(t, "DeployOn", output)
	assert.Regexp(t, "version advance", output)
	assert.Regexp(t, "build success", output)
}
Example #4
0
func TestBuildResultString(t *testing.T) {
	assert := assert.New(t)

	br := &BuildResult{
		Elapsed:     time.Second * 5,
		Advisories:  []string{"ephemeral tag"},
		VersionName: "something-something-2.3.4",
	}

	str := fmt.Sprintln(br)
	assert.Regexp(`ephemeral`, str)
	assert.Regexp(`2.3.4`, str)
	assert.Regexp(`5s`, str)
}
Example #5
0
func TestModifyImage(t *testing.T) {
	assert := assert.New(t)
	sous.Log.Warn.SetOutput(os.Stderr)
	Log.Debug.SetOutput(os.Stderr)

	before := "1.2.3-test"
	after := "2.3.4-new"
	pair := baseDeployablePair()
	pair.Prior.Deployment.SourceID.Version = semv.MustParse(before)
	pair.Post.Deployment.SourceID.Version = semv.MustParse(after)
	pair.Post.BuildArtifact.Name = "2.3.4"

	mods := make(chan *sous.DeployablePair, 1)
	errs := make(chan error, 10)

	client := sous.NewDummyRectificationClient()
	deployer := NewDeployer(client)

	mods <- pair
	close(mods)
	deployer.RectifyModifies(mods, errs)
	close(errs)

	for e := range errs {
		t.Error(e)
	}

	assert.Len(client.Created, 0)

	if assert.Len(client.Deployed, 1) {
		assert.Regexp("2.3.4", client.Deployed[0].ImageName)
	}
}
Example #6
0
func TestMetadataGetField(t *testing.T) {
	output := runCommand(t, []string{"BuildBranch"}, config.DeployFilterFlags{
		Repo: project1.Repo,
	})

	assert.Regexp(t, "master", output)
}
Example #7
0
func TestCanonName(t *testing.T) {
	assert := assert.New(t)

	vers, _ := semv.Parse("1.2.3-test+thing")
	dep := Deployment{
		SourceID: SourceID{
			Location: SourceLocation{
				Repo: "one",
				Dir:  "two",
			},
			Version: vers,
		},
	}
	str := dep.SourceID.Location.String()
	assert.Regexp("one", str)
	assert.Regexp("two", str)
}
Example #8
0
func TestMetadataGetFieldAndCluster(t *testing.T) {
	output := runCommand(t, []string{"DeployOn"}, config.DeployFilterFlags{
		Repo:    project1.Repo,
		Cluster: "cluster-2",
	})

	assert.Regexp(t, "version advance", output)
}
Example #9
0
func TestInvokeRectifyWithDebugFlags(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)

	_, exe, _, stderr := prepareCommand(t, []string{`sous`, `rectify`, `-d`, `-v`, `-all`})
	assert.Len(exe.Args, 0)
	require.IsType(&SousRectify{}, exe.Cmd)

	rect := exe.Cmd.(*SousRectify)

	assert.NotNil(rect.Config)
	assert.NotNil(rect.GDM)
	require.NotNil(rect.SourceFlags)
	assert.Equal(rect.SourceFlags.All, true)
	assert.Regexp(`Verbose debugging`, stderr.String())
	assert.Regexp(`Regular debugging`, stderr.String())
}
Example #10
0
func TestDeploymentDumper(t *testing.T) {
	assert := assert.New(t)

	io := &bytes.Buffer{}
	ds := NewDeployments()
	ds.Add(&Deployment{ClusterName: "andromeda"})

	DumpDeployments(io, ds)
	assert.Regexp(`andromeda`, io.String())
}
Example #11
0
func TestDump(t *testing.T) {
	assert := assert.New(t)

	io := &bytes.Buffer{}

	dc := docker_registry.NewDummyClient()
	nc := NewNameCache("", dc, inMemoryDB("dump"))

	nc.dump(io)
	assert.Regexp(`name_id`, io.String())
}
Example #12
0
func TestGetRunningDeploymentSet_testCluster(t *testing.T) {
	//sous.Log.Vomit.SetFlags(sous.Log.Vomit.Flags() | log.Ltime)
	//sous.Log.Vomit.SetOutput(os.Stderr)
	//sous.Log.Vomit.Print("Starting stderr output")
	sous.Log.Debug.SetFlags(sous.Log.Debug.Flags() | log.Ltime)
	sous.Log.Debug.SetOutput(os.Stderr)
	sous.Log.Debug.Print("Starting stderr output")
	assert := assert.New(t)

	registerLabelledContainers()
	drc := docker_registry.NewClient()
	drc.BecomeFoolishlyTrusting()
	nc := docker.NewNameCache("", drc, newInMemoryDB("grds"))
	client := singularity.NewRectiAgent()
	d := singularity.NewDeployer(client)

	clusters := []string{"test-cluster"}

	// We run this test more than once to check that cache behaviour is
	// consistent whether the cache is already warmed up or not.
	const numberOfTestRuns = 2

	for i := 0; i < numberOfTestRuns; i++ {
		ds, which := deploymentWithRepo(clusters, nc, assert, d, "github.com/opentable/docker-grafana")
		deps := ds.Snapshot()
		if assert.Equal(3, len(deps)) {
			grafana := deps[which]
			cacheHitText := fmt.Sprintf("on cache hit %d", i+1)
			assert.Equal(SingularityURL, grafana.Cluster.BaseURL, cacheHitText)
			assert.Regexp("^0\\.1", grafana.Resources["cpus"], cacheHitText)    // XXX strings and floats...
			assert.Regexp("^100\\.", grafana.Resources["memory"], cacheHitText) // XXX strings and floats...
			assert.Equal("1", grafana.Resources["ports"], cacheHitText)         // XXX strings and floats...
			assert.Equal(17, grafana.SourceID.Version.Patch, cacheHitText)
			assert.Equal("91495f1b1630084e301241100ecf2e775f6b672c", grafana.SourceID.Version.Meta, cacheHitText)
			assert.Equal(1, grafana.NumInstances, cacheHitText)
			assert.Equal(sous.ManifestKindService, grafana.Kind, cacheHitText)
		}
	}

	ResetSingularity()
}
Example #13
0
func TestInvokeWithUnknownFlags(t *testing.T) {
	log.SetFlags(log.Flags() | log.Lshortfile)
	assert := assert.New(t)
	require := require.New(t)

	stdin := &bytes.Buffer{}
	stdout := &bytes.Buffer{}
	stderr := &bytes.Buffer{}

	s := &Sous{Version: semv.MustParse(`1.2.3`)}
	c, err := NewSousCLI(s, stdin, stdout, stderr)
	require.NoError(err)

	c.Invoke([]string{`sous`, `-cobblers`})
	assert.Regexp(`flag provided but not defined`, stderr.String())
}
Example #14
0
func TestManifestGet(t *testing.T) {
	out := &bytes.Buffer{}
	smg := &SousManifestGet{
		TargetManifestID: graph.TargetManifestID{
			Source: sous.SourceLocation{
				Repo: project1.Repo,
			},
		},
		State:     makeTestState(),
		OutWriter: graph.OutWriter(out),
	}
	res := smg.Execute([]string{})
	assert.Equal(t, 0, res.ExitCode())

	assert.Regexp(t, "github", out.String())
}
Example #15
0
func TestModify(t *testing.T) {
	Log.Debug.SetOutput(os.Stderr)
	defer Log.Debug.SetOutput(ioutil.Discard)
	assert := assert.New(t)
	before := "1.2.3-test"
	after := "2.3.4-new"

	pair := baseDeployablePair()

	pair.Prior.Deployment.SourceID.Version = semv.MustParse(before)
	pair.Prior.Deployment.DeployConfig.NumInstances = 1
	pair.Prior.Deployment.DeployConfig.Volumes = sous.Volumes{{"host", "container", "RO"}}

	pair.Post.Deployment.SourceID.Version = semv.MustParse(after)
	pair.Post.Deployment.DeployConfig.NumInstances = 24
	pair.Post.Deployment.DeployConfig.Volumes = sous.Volumes{{"host", "container", "RW"}}
	pair.Post.BuildArtifact.Name = "2.3.4"

	mods := make(chan *sous.DeployablePair, 1)
	errs := make(chan error, 10)

	client := sous.NewDummyRectificationClient()
	deployer := NewDeployer(client)

	mods <- pair
	close(mods)
	deployer.RectifyModifies(mods, errs)
	close(errs)

	for e := range errs {
		t.Error(e)
	}

	if assert.Len(client.Created, 1) {
		assert.Equal(24, client.Created[0].Count)
	}

	if assert.Len(client.Deployed, 1) {
		assert.Regexp("2.3.4", client.Deployed[0].ImageName)
		log.Print(client.Deployed[0].Vols)
		assert.Equal("RW", string(client.Deployed[0].Vols[0].Mode))
	}

}
Example #16
0
func TestOverallRouter(t *testing.T) {
	assert := assert.New(t)

	gf := func() Injector {
		g := graph.BuildGraph(&bytes.Buffer{}, os.Stdout, os.Stdout)
		g.Add(&config.Verbosity{})
		return g
	}
	ts := httptest.NewServer(SousRouteMap.BuildRouter(gf))
	defer ts.Close()

	res, err := http.Get(ts.URL + "/gdm")
	assert.NoError(err)
	gdm, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	assert.NoError(err)
	assert.Regexp(`"Deployments"`, string(gdm))
	assert.NotEqual(res.Header.Get("Etag"), "")
}
Example #17
0
func assertSourceContextError(t *testing.T, flags *sous.ResolveFilter, ctx *SourceContextDiscovery, msgPattern string) {
	_, actualErr := newTargetManifestID(flags, ctx)
	assert.NotNil(t, actualErr)
	assert.Regexp(t, msgPattern, actualErr.Error())
}
Example #18
0
// Regexp asserts that a specified regexp matches a string.
//
//  assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
//  assert.Regexp(t, "start...$", "it's not starting")
//
// Returns whether the assertion was successful (true) or not (false).
func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
	if !assert.Regexp(t, rx, str, msgAndArgs...) {
		t.FailNow()
	}
}