예제 #1
0
파일: cli_test.go 프로젝트: opentable/sous
func TestInvokeServer(t *testing.T) {
	exe := justCommand(t, []string{`sous`, `server`})
	assert.NotNil(t, exe)

	exe = justCommand(t, []string{`sous`, `server`, `-cluster`, `test`})
	assert.NotNil(t, exe)
}
예제 #2
0
파일: cli_test.go 프로젝트: opentable/sous
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
파일: cli_test.go 프로젝트: opentable/sous
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
파일: cli_test.go 프로젝트: opentable/sous
func TestInvokeQuery(t *testing.T) {
	assert := assert.New(t)

	exe := justCommand(t, []string{`sous`, `query`})
	assert.NotNil(exe)

	exe = justCommand(t, []string{`sous`, `query`, `ads`})
	assert.NotNil(exe)

	exe = justCommand(t, []string{`sous`, `query`, `gdm`})
	assert.NotNil(exe)
}
예제 #5
0
파일: cli_test.go 프로젝트: opentable/sous
/*
usage: sous build [path]

build builds the project in your current directory by default. If you pass it a
path, it will instead build the project at that path.

options:
  -offset string
    	source code relative repository offset
  -repo string
    	source code repository location
  -revision string
    	source code revision ID
  -strict
    	require that the build be pristine
  -tag string
    	source code revision tag

*/
func TestInvokeBuildWithRepoSelector(t *testing.T) {
	assert := assert.New(t)

	_, exe, _, _ := prepareCommand(t, []string{`sous`, `build`, `-repo`, `github.com/opentable/sous`})
	assert.Len(exe.Args, 0)

	build := exe.Cmd.(*SousBuild)

	assert.NotNil(build.Labeller)
	assert.NotNil(build.Registrar)
	assert.Equal(build.DeployFilterFlags.Repo, `github.com/opentable/sous`)

}
예제 #6
0
파일: cli_test.go 프로젝트: opentable/sous
func TestInvokeHarvest(t *testing.T) {
	assert := assert.New(t)

	exe := justCommand(t, []string{`sous`, `harvest`, `sms-continual-test`})
	assert.NotNil(exe)
	assert.Len(exe.Args, 1)
}
예제 #7
0
파일: cli_test.go 프로젝트: opentable/sous
/*
usage: sous config Invoking sous config with no arguments lists all configuration key/value pairs.
If you pass just a single argument (a key) sous config will output just the
value of that key. You can set a key by providing both a key and a value.

usage: sous config [<key> [value]]

*/
func TestInvokeConfig(t *testing.T) {
	assert := assert.New(t)

	exe := justCommand(t, []string{`sous`, `config`})
	assert.NotNil(exe)
	assert.Len(exe.Args, 0)

	exe = justCommand(t, []string{`sous`, `config`, `x`})
	assert.NotNil(exe)
	assert.Len(exe.Args, 1)

	exe = justCommand(t, []string{`sous`, `config`, `x`, `7`})
	assert.NotNil(exe)
	assert.Len(exe.Args, 2)

}
예제 #8
0
파일: cli_test.go 프로젝트: opentable/sous
func TestInvokeUpdate(t *testing.T) {
	assert := assert.New(t)

	exe := justCommand(t, []string{`sous`, `update`})
	assert.NotNil(exe)
	assert.Len(exe.Args, 0)
}
예제 #9
0
파일: cli_test.go 프로젝트: opentable/sous
/*
usage: sous context

context prints out sous's view of your current context
*/
func TestInvokeContext(t *testing.T) {
	assert := assert.New(t)

	exe := justCommand(t, []string{`sous`, `context`})
	assert.NotNil(exe)
	assert.Len(exe.Args, 0)
}
예제 #10
0
func TestCanMakeAnAgent(t *testing.T) {
	assert := assert.New(t)

	agent, err := NewAgent()
	assert.NoError(err)
	assert.NotNil(agent)
}
예제 #11
0
// This test is terrible, but the current design of the client is hard to test
func TestNewClient(t *testing.T) {
	assert := assert.New(t)

	c := NewClient()
	assert.NotNil(c)
	c.Cancel()
}
예제 #12
0
파일: cli_test.go 프로젝트: opentable/sous
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())
}
예제 #13
0
파일: cli_test.go 프로젝트: opentable/sous
func TestInvokeRectifyWithoutFilterFlags(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)

	_, exe, _, _ := prepareCommand(t, []string{`sous`, `rectify`})
	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, false)
	require.NotNil(rect.Resolver.ResolveFilter)
	assert.Equal(rect.Resolver.ResolveFilter.All(), true)
}
예제 #14
0
func TestGetDepSetWorks(t *testing.T) {
	assert := assert.New(t)

	Log.Debug.SetOutput(os.Stderr)

	whip := make(map[string]swaggering.DummyControl)

	reg := sous.NewDummyRegistry()
	client := sous.NewDummyRectificationClient()
	dep := deployer{client,
		func(url string) *singularity.Client {
			cl, co := singularity.NewDummyClient(url)

			co.FeedDTO(&dtos.SingularityRequestParentList{
				&dtos.SingularityRequestParent{
					RequestDeployState: &dtos.SingularityRequestDeployState{
						ActiveDeploy: &dtos.SingularityDeployMarker{
							DeployId:  "testdep",
							RequestId: "testreq",
						},
					},
					Request: &dtos.SingularityRequest{
						Id:          "testreq",
						RequestType: dtos.SingularityRequestRequestTypeSERVICE,
						Owners:      swaggering.StringList{"*****@*****.**"},
					},
				},
			}, nil)

			co.FeedDTO(&dtos.SingularityDeployHistory{
				Deploy: &dtos.SingularityDeploy{
					Id: "testdep",
					ContainerInfo: &dtos.SingularityContainerInfo{
						Type:   dtos.SingularityContainerInfoSingularityContainerTypeDOCKER,
						Docker: &dtos.SingularityDockerInfo{},
						Volumes: dtos.SingularityVolumeList{
							&dtos.SingularityVolume{
								HostPath:      "/onhost",
								ContainerPath: "/indocker",
								Mode:          dtos.SingularityVolumeSingularityDockerVolumeModeRW,
							},
						},
					},
					Resources: &dtos.Resources{},
				},
			}, nil)

			whip[url] = co
			return cl
		},
	}

	clusters := sous.Clusters{"test": {BaseURL: "http://test-singularity.org/"}}
	res, err := dep.RunningDeployments(reg, clusters)
	assert.NoError(err)
	assert.NotNil(res)
}
예제 #15
0
파일: cli_test.go 프로젝트: opentable/sous
func TestInvokeInit(t *testing.T) {
	assert := assert.New(t)

	exe := justCommand(t, []string{`sous`, `init`})
	init := exe.Cmd.(*SousInit)
	assert.NotNil(init)
	assert.False(init.Flags.IgnoreOTPLDeploy)
	assert.False(init.Flags.IgnoreOTPLDeploy)
}
예제 #16
0
파일: cli_test.go 프로젝트: opentable/sous
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`)
}
예제 #17
0
func TestAllowsWhitelistedAdvisories(t *testing.T) {
	assert := assert.New(t)

	svOne := MustParseSourceID(`github.com/ot/one,1.3.5`)
	dr := NewDummyRegistry()
	config := DeployConfig{NumInstances: 1}
	intoCI := Deployment{ClusterName: `ci`, Cluster: &Cluster{AllowedAdvisories: []string{"ephemeral_tag"}}, SourceID: svOne, DeployConfig: config}

	dr.FeedArtifact(&BuildArtifact{"ot-docker/one", "docker", []Quality{{"ephemeral_tag", "advisory"}}}, nil)

	art, err := GuardImage(dr, &intoCI)
	assert.NoError(err)
	assert.NotNil(art)
}
예제 #18
0
func TestBuildDeployRequest(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)

	di := "dockerImage"
	rID := "reqID"
	env := sous.Env{"test": "yes"}
	rez := sous.Resources{"cpus": "0.1"}
	vols := sous.Volumes{&sous.Volume{}}

	dr, err := buildDeployRequest(di, env, rez, rID, vols)
	require.NoError(err)
	assert.NotNil(dr)
	assert.Equal(dr.Deploy.RequestId, rID)
}
예제 #19
0
// This can happen e.g. if the same source gets built twice
func TestSecondCanonicalName(t *testing.T) {
	assert := assert.New(t)

	dc := docker_registry.NewDummyClient()

	host := "docker.repo.io"
	base := "ot/wackadoo"
	nc := NewNameCache(host, dc, inMemoryDB("secondCN"))

	repo := "github.com/opentable/test-app"

	stuffBA := func(digest string) sous.SourceID {
		n := "test-service"
		v := `0.1.2-ci1234`
		ba := &sous.BuildArtifact{
			Name: n,
			Type: "docker",
		}

		sv := sous.MustNewSourceID(repo, "", v)

		in := base + ":version-" + v
		cn := base + "@sha256:" + digest

		dc.FeedMetadata(docker_registry.Metadata{
			Registry:      host,
			Labels:        Labels(sv),
			Etag:          digest,
			CanonicalName: cn,
			AllNames:      []string{cn, in},
		})
		sid, err := nc.GetSourceID(ba)
		if !assert.NoError(err) {
			fmt.Println(err)
			nc.dump(os.Stderr)
		}
		assert.NotNil(sid)
		return sid
	}
	sid1 := stuffBA(`012345678901234567890123456789AB012345678901234567890123456789AB`)
	sid2 := stuffBA(`ABCDEFABCDEFABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEF12341234566`)

	_, err := nc.GetArtifact(sid1) //which should not miss
	assert.NoError(err)

	_, err = nc.GetArtifact(sid2) //which should not miss
	assert.NoError(err)
}
예제 #20
0
// I'm still exploring what the problem is here...
func TestHarvestAlso(t *testing.T) {
	assert := assert.New(t)

	dc := docker_registry.NewDummyClient()

	host := "docker.repo.io"
	base := "ot/wackadoo"
	repo := "github.com/opentable/test-app"

	nc := NewNameCache(host, dc, inMemoryDB("harvest_also"))

	stuffBA := func(n, v string) sous.SourceID {
		ba := &sous.BuildArtifact{
			Name: n,
			Type: "docker",
		}

		sv := sous.MustNewSourceID(repo, "", v)

		in := base + ":version-" + v
		digBs := sha256.Sum256([]byte(in))
		digest := hex.EncodeToString(digBs[:])
		cn := base + "@sha256:" + digest

		dc.FeedMetadata(docker_registry.Metadata{
			Registry:      host,
			Labels:        Labels(sv),
			Etag:          digest,
			CanonicalName: cn,
			AllNames:      []string{cn, in},
		})
		sid, err := nc.GetSourceID(ba)
		assert.NoError(err)
		assert.NotNil(sid)
		return sid
	}
	sid1 := stuffBA("tom", "0.2.1")
	sid2 := stuffBA("dick", "0.2.2")
	sid3 := stuffBA("harry", "0.2.3")

	_, err := nc.GetArtifact(sid1) //which should not miss
	assert.NoError(err)
	_, err = nc.GetArtifact(sid2) //which should not miss
	assert.NoError(err)
	_, err = nc.GetArtifact(sid3) //which should not miss
	assert.NoError(err)
}
예제 #21
0
파일: require.go 프로젝트: opentable/sous
// NotNil asserts that the specified object is not nil.
//
//    assert.NotNil(t, err, "err should be something")
//
// Returns whether the assertion was successful (true) or not (false).
func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
	if !assert.NotNil(t, object, msgAndArgs...) {
		t.FailNow()
	}
}
예제 #22
0
파일: cli_test.go 프로젝트: opentable/sous
func TestInvokeQueryArtifacts(t *testing.T) {
	assert := assert.New(t)

	exe := justCommand(t, []string{`sous`, `query`, `artifacts`})
	assert.NotNil(exe)
}
예제 #23
0
파일: cli_test.go 프로젝트: opentable/sous
func TestInvokeVersion(t *testing.T) {
	assert := assert.New(t)

	exe := justCommand(t, []string{`sous`, `version`})
	assert.NotNil(exe)
}
예제 #24
0
func TestPredicateBuilder(t *testing.T) {
	assert := assert.New(t)

	ds := make([]*sous.Deployment, 0, 8)
	cs := []string{"cluster1", "cluster2"}
	rs := []string{"github.com/ot/one", "github.com/ot/two"}
	os := []string{"up", "down"}

	for _, c := range cs {
		for _, r := range rs {
			for _, o := range os {
				ds = append(ds, &sous.Deployment{
					ClusterName: c,
					SourceID: sous.SourceID{
						Location: sous.SourceLocation{
							Repo: r,
							Dir:  o,
						},
					},
				})
			}
		}
	}

	parseSL := func(string) (sous.SourceLocation, error) {
		return sous.SourceLocation{}, nil
	}

	//	for i, d := range ds {
	//		fmt.Printf("%d: %#v\n", i, d)
	//	}
	//
	f := config.DeployFilterFlags{}

	rf, err := f.BuildFilter(parseSL)
	assert.NoError(err)
	assert.True(rf.All())

	f.Repo = string(rs[0])
	pd, err := f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered := filter(ds, pd)
	assert.Contains(filtered, ds[0])
	assert.Contains(filtered, ds[1])
	assert.Contains(filtered, ds[4])
	assert.Contains(filtered, ds[5])
	assert.Len(filtered, 4)

	f.Offset = string(os[0])
	pd, err = f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered = filter(ds, pd)
	assert.Contains(filtered, ds[0])
	assert.Contains(filtered, ds[4])
	assert.Len(filtered, 2)

	f.Cluster = cs[0]
	pd, err = f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered = filter(ds, pd)
	assert.Contains(filtered, ds[0])
	assert.Len(filtered, 1)

	f = config.DeployFilterFlags{Cluster: cs[1]}
	pd, err = f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered = filter(ds, pd)
	assert.Contains(filtered, ds[4])
	assert.Contains(filtered, ds[5])
	assert.Contains(filtered, ds[6])
	assert.Contains(filtered, ds[7])
	assert.Len(filtered, 4)

	f = config.DeployFilterFlags{All: true}
	pd, err = f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered = filter(ds, pd)
	assert.Len(filtered, 8)
}
예제 #25
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())
}