示例#1
0
func TestOwnerSet(t *testing.T) {
	set := NewOwnerSet("one")
	set.Add("two")
	set.Add("one")
	slice := set.Slice()
	assert.Len(t, slice, 2)
	assert.Contains(t, slice, "one")
	assert.Contains(t, slice, "two")
	assert.True(t, set.Equal(NewOwnerSet("two", "one")))
}
示例#2
0
func TestUnion(t *testing.T) {
	assert := assert.New(t)

	left := []string{"a", "b", "c"}
	right := []string{"b", "c", "d"}

	all := union(left, right)
	assert.Equal(len(all), 4)
	assert.Contains(all, "a")
	assert.Contains(all, "b")
	assert.Contains(all, "c")
	assert.Contains(all, "d")
}
示例#3
0
func TestClusterMap(t *testing.T) {
	assert := assert.New(t)

	s := State{
		Defs: Defs{
			Clusters: Clusters{
				"one": &Cluster{},
				"two": &Cluster{},
			},
		},
	}

	m := s.ClusterMap()
	assert.Len(m, 2)
	assert.Contains(m, "one")
	assert.Contains(m, "two")
}
示例#4
0
func TestRemoteProcessing(t *testing.T) {
	assert := assert.New(t)

	rs := Remotes{
		`origin`: Remote{
			Name:     `origin`,
			FetchURL: `https://github.com/origin/fetch`,
			PushURL:  `https://github.com/origin/push`,
		},
		`upstream`: Remote{
			Name:     `upstream`,
			FetchURL: `https://github.com/upstream/fetch.git`,
			PushURL:  `https://github.com/upstream/push.git`,
		},
		`something`: Remote{
			Name:     `something`,
			FetchURL: `[email protected]:something/fetch.git`,
			PushURL:  `[email protected]:something/push.git`,
		},
	}

	assert.Equal(`github.com/upstream/fetch`, guessPrimaryRemote(rs))
	afs := allFetchURLs(rs)
	assert.Contains(afs, `github.com/origin/fetch`)
	assert.NotContains(afs, `github.com/origin/push`)
	assert.Contains(afs, `github.com/upstream/fetch`)
	assert.NotContains(afs, `github.com/upstream/push`)
	assert.Contains(afs, `github.com/something/fetch`)
	assert.NotContains(afs, `github.com/something/push`)

	delete(rs, `upstream`)
	assert.Equal(`github.com/origin/fetch`, guessPrimaryRemote(rs))
	afs = allFetchURLs(rs)
	assert.Contains(afs, `github.com/origin/fetch`)
	assert.NotContains(afs, `github.com/upstream/fetch`)

	delete(rs, `origin`)
	assert.Equal(``, guessPrimaryRemote(rs))
	afs = allFetchURLs(rs)
	assert.NotContains(afs, `github.com/upstream/fetch`)
	assert.Contains(afs, `github.com/something/fetch`)
}
示例#5
0
func TestGetLabels(t *testing.T) {
	registerLabelledContainers()
	assert := assert.New(t)
	cl := docker_registry.NewClient()
	cl.BecomeFoolishlyTrusting()

	labels, err := cl.LabelsForImageName(imageName)

	assert.Nil(err)
	assert.Contains(labels, docker.DockerRepoLabel)
	ResetSingularity()
}
示例#6
0
func TestAdvisesOfDefaultVersion(t *testing.T) {
	assert := assert.New(t)

	bc := BuildConfig{
		Context: &BuildContext{
			Sh: &shell.Sh{},
			Source: SourceContext{
				Revision: "abcd",
			},
		},
	}

	ctx := bc.NewContext()
	assert.Equal(`0.0.0-unversioned+abcd`, ctx.Source.Version().Version.String())
	assert.Contains(ctx.Advisories, string(Unversioned))
}
示例#7
0
func TestDirtyWorkspaceAdvisory(t *testing.T) {
	assert := assert.New(t)

	bc := BuildConfig{
		Context: &BuildContext{
			Sh: &shell.Sh{},
			Source: SourceContext{
				DirtyWorkingTree: true,
			},
		},
	}

	ctx := bc.NewContext()
	assert.Contains(ctx.Advisories, string(DirtyWS))
	assert.Error(bc.GuardRegister(ctx))
}
示例#8
0
func TestPermissiveGuard(t *testing.T) {
	assert := assert.New(t)

	bc := BuildConfig{
		Strict: false,
		Context: &BuildContext{
			Sh: &shell.Sh{},
			Source: SourceContext{
				RevisionUnpushed: true,
			},
		},
	}

	ctx := bc.NewContext()
	assert.Contains(ctx.Advisories, string(UnpushedRev))
	assert.NoError(bc.GuardStrict(ctx))
}
示例#9
0
func TestParseTags(t *testing.T) {
	assert := assert.New(t)

	lines := []string{
		"2f381f35ffcf57b21b4c2991635f7f825c29f003 2016-08-02T11:16:04-04:00 HEAD -> master, tag: 0.2.0, origin/master, origin/HEAD",
		"0a271b999974db8f37326e16c9027436098b251f 2016-08-01T10:54:53-04:00 tag: 0.1.6",
		"a83cebbdb1e06bc325f88d953120ac60dead7268 2016-07-26T15:32:24-04:00 tag: 0.1.5",
		"65017e8bcbeaf10d48ea677113a3d5d99ed03c45 2016-07-12T14:23:03-04:00 tag: 0.1.4",
		"6013d74276ac6a62f8fec3aee7c06162496b25a5 2016-07-12T13:14:52-04:00 tag: 0.1.3",
		"b779b60a13f0a3b8edbecf81b0b24b252202b3a2 2016-07-11T16:00:14-04:00 tag: 0.1.2",
		"612eec227ccdcdbe9d182ce830adb566930ca0c0 2016-07-07T14:41:18-04:00 2f381f35ffcf57b21b4c2991635f7f825c29f003",
	}

	tags := (&Client{}).parseTags(lines)
	assert.Len(tags, 6)
	assert.Contains(tags, sous.Tag{Name: "0.2.0", Revision: "2f381f35ffcf57b21b4c2991635f7f825c29f003"})
}
示例#10
0
func TestEphemeralTag(t *testing.T) {
	assert := assert.New(t)

	bc := BuildConfig{
		Tag: "1.2.3",
		Context: &BuildContext{
			Sh: &shell.Sh{},
			Source: SourceContext{
				PrimaryRemoteURL:   "github.com/opentable/present",
				Revision:           "abcd",
				NearestTagName:     "1.2.0",
				NearestTagRevision: "3541",
			},
		},
	}
	/*
		bc := BuildConfig{
			Strict:   true,
			Tag:      "1.2.3",
			Repo:     "github.com/opentable/present",
			Revision: "abcdef",
			Context: &BuildContext{
			Sh: &shell.Sh{},
				Source: SourceContext{
					RemoteURL: "github.com/opentable/present",
					RemoteURLs: []string{
						"github.com/opentable/present",
						"github.com/opentable/also",
					},
					Revision:           "abcdef",
					NearestTagName:     "1.2.3",
					NearestTagRevision: "abcdef",
					Tags: []Tag{
						Tag{Name: "1.2.3"},
					},
				},
			},
		}
	*/

	ctx := bc.NewContext()
	assert.Equal(`1.2.3+abcd`, ctx.Source.Version().Version.String())
	assert.Contains(ctx.Advisories, string(EphemeralTag))
	assert.NotContains(ctx.Advisories, string(TagNotHead))
	assert.NoError(bc.GuardRegister(ctx))
}
示例#11
0
// If a revision is specified, but that's not what's checked out,
// add an advisory
func TestNotRequestedRevision(t *testing.T) {
	assert := assert.New(t)

	bc := BuildConfig{
		Revision: "abcdef",
		Context: &BuildContext{
			Sh: &shell.Sh{},
			Source: SourceContext{
				Revision: "100100100",
			},
		},
	}

	ctx := bc.NewContext()
	assert.Equal(`100100100`, ctx.Source.Revision)
	assert.Contains(ctx.Advisories, string(NotRequestedRevision))

}
示例#12
0
// If neither are present on the current workspace (or we're not in a
// git workspace), add the advisory "no repo."
func TestNoRepo(t *testing.T) {
	assert := assert.New(t)

	bc := BuildConfig{
		Repo: "",
		Context: &BuildContext{
			Sh: &shell.Sh{},
			Source: SourceContext{
				PrimaryRemoteURL: "",
				RemoteURLs: []string{
					"github.com/opentable/also",
				},
			},
		},
	}

	ctx := bc.NewContext()
	assert.Contains(ctx.Advisories, string(NoRepoAdv))
}
示例#13
0
// If it's absent, we'll be building from a shallow
// clone of the given --repo.
func TestMissingExplicitRepo(t *testing.T) {
	assert := assert.New(t)

	bc := BuildConfig{
		Repo: "github.com/opentable/present",
		Context: &BuildContext{
			Sh: &shell.Sh{},
			Source: SourceContext{
				PrimaryRemoteURL: "github.com/guessed/upstream",
				RemoteURLs: []string{
					"github.com/opentable/also",
				},
			},
		},
	}

	ctx := bc.NewContext()
	assert.Equal(`github.com/opentable/present`, ctx.Source.RemoteURL)
	assert.Contains(ctx.Advisories, string(UnknownRepo))
}
示例#14
0
func sameYAML(t *testing.T, actual *sous.State, expected *sous.State) {
	assert := assert.New(t)
	require := require.New(t)

	actualManifests := actual.Manifests.Snapshot()
	expectedManifests := expected.Manifests.Snapshot()
	assert.Len(actualManifests, len(expectedManifests))
	for mid, manifest := range expectedManifests {
		actual := *actualManifests[mid]
		assert.Contains(actualManifests, mid)
		if !assert.Equal(actual, *manifest) {
			_, differences := actual.Diff(manifest)
			t.Logf("DIFFERENCES (%q): %#v", mid, differences)
		}
	}

	actualYAML, err := yaml.Marshal(actual)
	require.NoError(err)
	expectedYAML, err := yaml.Marshal(expected)
	require.NoError(err)
	assert.Equal(actualYAML, expectedYAML)
}
示例#15
0
func TestTagNotHead(t *testing.T) {
	assert := assert.New(t)

	bc := BuildConfig{
		Tag: "1.2.3",
		Context: &BuildContext{
			Sh: &shell.Sh{},
			Source: SourceContext{
				Revision:           "abcd",
				NearestTagName:     "1.2.3",
				NearestTagRevision: "def0",
				Tags: []Tag{
					Tag{Name: "1.2.3"},
				},
			},
		},
	}

	ctx := bc.NewContext()
	assert.Equal(`1.2.3+abcd`, ctx.Source.Version().Version.String())
	assert.Contains(ctx.Advisories, string(TagNotHead))
	assert.NotContains(ctx.Advisories, string(EphemeralTag))
}
示例#16
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)
}
示例#17
0
文件: require.go 项目: opentable/sous
// Contains asserts that the specified string, list(array, slice...) or map contains the
// specified substring or element.
//
//    assert.Contains(t, "Hello World", "World", "But 'Hello World' does contain 'World'")
//    assert.Contains(t, ["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'")
//    assert.Contains(t, {"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'")
//
// Returns whether the assertion was successful (true) or not (false).
func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
	if !assert.Contains(t, s, contains, msgAndArgs...) {
		t.FailNow()
	}
}