示例#1
0
func TestManifestSet(t *testing.T) {
	mid := sous.ManifestID{
		Source: sous.SourceLocation{
			Repo: project1.Repo,
		},
	}
	baseState := makeTestState()
	mani, present := baseState.Manifests.Get(mid)
	require.True(t, present)
	mani.Flavor = "vanilla"
	yml, err := yaml.Marshal(mani)
	require.NoError(t, err)
	in := bytes.NewBuffer(yml)

	state := makeTestState()

	dummyWriter := sous.DummyStateManager{State: state}
	writer := graph.StateWriter{StateWriter: &dummyWriter}
	sms := &SousManifestSet{
		TargetManifestID: graph.TargetManifestID(mid),
		State:            state,
		InReader:         graph.InReader(in),
		StateWriter:      writer,
	}

	assert.Equal(t, 0, dummyWriter.WriteCount)
	res := sms.Execute([]string{})
	assert.Equal(t, 0, res.ExitCode())
	assert.Equal(t, 1, dummyWriter.WriteCount)

	upManifest, present := state.Manifests.Get(mid)
	require.True(t, present)
	assert.Equal(t, upManifest.Flavor, "vanilla")

}
示例#2
0
func TestInvokeManifestSet(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)
	exe := justCommand(t, []string{`sous`, `manifest`, `set`, `-repo`, `github.com/opentable/sous`})
	assert.NotNil(exe)
	maniSet, good := exe.Cmd.(*SousManifestSet)
	require.True(good)
	assert.NotNil(maniSet.StateWriter)
}
示例#3
0
func TestInvokeMetadataSet(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)
	exe := justCommand(t, []string{`sous`, `metadata`, `set`, `-repo`, `github.com/opentable/sous`, `BuildBranch`, `master`})
	assert.NotNil(exe)
	metaSet, good := exe.Cmd.(*SousMetadataSet)
	require.True(good)
	assert.NotNil(metaSet.State)
}
示例#4
0
func TestInvokeDeploy(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)

	exe := justCommand(t, []string{`sous`, `deploy`, `-cluster`, `ci-sf`, `-tag`, `1.2.3`})
	assert.NotNil(exe)
	assert.Len(exe.Args, 0)
	deploy, good := exe.Cmd.(*SousDeploy)
	require.True(good)
	assert.Equal(deploy.DeployFilterFlags.Cluster, `ci-sf`)
	assert.Equal(deploy.DeployFilterFlags.Tag, `1.2.3`)
}
示例#5
0
func TestHandlesManifestPut(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)

	q, err := url.ParseQuery("repo=gh")
	require.NoError(err)
	state := sous.NewState()
	state.Manifests.Add(&sous.Manifest{
		Source: sous.SourceLocation{Repo: "gh"},
		Kind:   sous.ManifestKindService,
	})
	writer := graph.StateWriter{StateWriter: &sous.DummyStateManager{State: state}}

	manifest := &sous.Manifest{
		Source: sous.SourceLocation{Repo: "gh"},
		Owners: []string{"sam", "judson"},
		Kind:   sous.ManifestKindService,
	}
	buf := &bytes.Buffer{}
	enc := json.NewEncoder(buf)
	enc.Encode(manifest)
	req, err := http.NewRequest("PUT", "", buf)
	require.NoError(err)

	th := &PUTManifestHandler{
		Request:     req,
		StateWriter: writer,
		State:       state,
		QueryValues: &QueryValues{q},
	}
	data, status := th.Exchange()
	assert.Equal(status, 200)
	require.IsType(&sous.Manifest{}, data)
	assert.Len(data.(*sous.Manifest).Owners, 2)
	assert.Equal(data.(*sous.Manifest).Owners[1], "judson")

	changed, found := state.Manifests.Get(sous.ManifestID{Source: sous.SourceLocation{Repo: "gh"}})
	require.True(found)
	assert.Len(changed.Owners, 2)
	assert.Equal(changed.Owners[1], "judson")

}