當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.Equal函數代碼示例

本文整理匯總了Golang中github.com/nyarly/testify/assert.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestQueryValuesToManifestIDHappyPath

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

	pq := func(s string) *QueryValues {
		v, _ := url.ParseQuery(s)
		return &QueryValues{v}
	}
	ev := func(x interface{}, e error) error {
		return e
	}
	mid := func(v sous.ManifestID, e error) sous.ManifestID {
		return v
	}

	assert.NoError(ev(manifestIDFromValues(pq("repo=gh1"))))
	assert.NoError(ev(manifestIDFromValues(pq("repo=gh1&offset=o1"))))
	assert.NoError(ev(manifestIDFromValues(pq("repo=gh1&offset=o1&flavor=f1"))))

	assert.Equal(
		mid(manifestIDFromValues(pq("repo=gh1"))),
		sous.ManifestID{Source: sous.SourceLocation{Repo: "gh1"}})

	assert.Equal(
		mid(manifestIDFromValues(pq("repo=gh1&offset=o1"))),
		sous.ManifestID{Source: sous.SourceLocation{Repo: "gh1", Dir: "o1"}})

	assert.Equal(
		mid(manifestIDFromValues(pq("repo=gh1&offset=o1&flavor=f1"))),
		sous.ManifestID{Source: sous.SourceLocation{Repo: "gh1", Dir: "o1"}, Flavor: "f1"})
}
開發者ID:opentable,項目名稱:sous,代碼行數:30,代碼來源:handle_manifest_test.go

示例2: TestBuildDeployment

func TestBuildDeployment(t *testing.T) {
	assert := assert.New(t)
	m := &Manifest{
		Source: SourceLocation{},
		Owners: []string{"[email protected]"},
		Kind:   ManifestKindService,
	}
	sp := DeploySpec{
		DeployConfig: DeployConfig{
			Resources:    Resources{},
			Args:         []string{},
			Env:          Env{},
			NumInstances: 3,
			Volumes: Volumes{
				&Volume{"h", "c", "RO"},
			},
		},
		Version:     semv.MustParse("1.2.3"),
		clusterName: "cluster.name",
	}
	var ih []DeploySpec
	nick := "cn"

	state := &State{Defs: Defs{Clusters: Clusters{nick: &Cluster{BaseURL: "http://not"}}}}

	d, err := BuildDeployment(state, m, nick, sp, ih)

	if assert.NoError(err) {
		if assert.Len(d.DeployConfig.Volumes, 1) {
			assert.Equal("c", d.DeployConfig.Volumes[0].Container)
		}
		assert.Equal(nick, d.ClusterName)
	}
}
開發者ID:opentable,項目名稱:sous,代碼行數:34,代碼來源:deployment_test.go

示例3: TestManifestSet

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")

}
開發者ID:opentable,項目名稱:sous,代碼行數:35,代碼來源:sous_manifest_test.go

示例4: assertSourceContextSuccess

func assertSourceContextSuccess(t *testing.T, expected sous.ManifestID, flags *sous.ResolveFilter, ctx *sous.SourceContext) {
	disco := &SourceContextDiscovery{SourceContext: ctx}
	actual, err := newTargetManifestID(flags, disco)
	require.NoError(t, err)
	assert.Equal(t, actual.Source.Repo, expected.Source.Repo, "repos differ")
	assert.Equal(t, actual.Source.Dir, expected.Source.Dir, "offsets differ")
	assert.Equal(t, actual.Flavor, expected.Flavor, "flavors differ")
}
開發者ID:opentable,項目名稱:sous,代碼行數:8,代碼來源:sourcecontext_test.go

示例5: TestInvokeDeploy

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`)
}
開發者ID:opentable,項目名稱:sous,代碼行數:12,代碼來源:cli_test.go

示例6: TestTagStrings

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

	sid, err := sous.NewSourceID("github.com/opentable/sous", "docker", "1.2.3+deadbeef")
	if err != nil {
		t.Fatal(err)
	}

	assert.Equal("/sous/docker:1.2.3", versionName(sid))
	assert.Equal("/sous/docker:deadbeef", revisionName(sid))

}
開發者ID:opentable,項目名稱:sous,代碼行數:12,代碼來源:builder_test.go

示例7: TestVersion

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

	sc := SourceContext{
		OffsetDir:      "sub",
		RemoteURL:      "github.com/opentable/test",
		NearestTagName: "1.2.3",
	}
	id := sc.Version()
	assert.Equal("github.com/opentable/test", id.Location.Repo)
	assert.Equal("sub", string(id.Location.Dir))
	assert.Equal("1.2.3", id.Version.String())
}
開發者ID:opentable,項目名稱:sous,代碼行數:13,代碼來源:source_context_test.go

示例8: TestValidateRepairResources

func TestValidateRepairResources(t *testing.T) {
	empty := make(Resources)

	flaws := empty.Validate()
	assert.Len(t, flaws, 3)

	flaws, es := RepairAll(flaws)
	assert.Len(t, flaws, 0)
	assert.Len(t, es, 0)
	assert.Equal(t, empty["cpus"], "0.1")
	assert.Equal(t, empty["memory"], "100")
	assert.Equal(t, empty["ports"], "1")
}
開發者ID:opentable,項目名稱:sous,代碼行數:13,代碼來源:resources_test.go

示例9: TestCreates

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

	created := &sous.Deployable{
		BuildArtifact: &sous.BuildArtifact{
			Type: "docker",
			Name: "reqid,0.0.0",
		},
		Deployment: &sous.Deployment{
			SourceID: sous.SourceID{
				Location: sous.SourceLocation{
					Repo: "reqid",
				},
			},
			DeployConfig: sous.DeployConfig{
				NumInstances: 12,
			},
			Cluster:     &sous.Cluster{BaseURL: "cluster"},
			ClusterName: "nick",
		},
	}

	crts := make(chan *sous.Deployable, 1)
	errs := make(chan error, 10)

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

	crts <- created
	close(crts)
	deployer.RectifyCreates(crts, errs)
	close(errs)

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

	if assert.Len(client.Deployed, 1) {
		dep := client.Deployed[0]
		assert.Equal("cluster", dep.Cluster)
		assert.Equal("reqid,0.0.0", dep.ImageName)
	}

	if assert.Len(client.Created, 1) {
		req := client.Created[0]
		assert.Equal("cluster", req.Cluster)
		assert.Equal("reqid::nick", req.ID)
		assert.Equal(12, req.Count)
	}
}
開發者ID:opentable,項目名稱:sous,代碼行數:50,代碼來源:rectifier_test.go

示例10: TestMetadataDockerfile

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

	b := Builder{}

	br := sous.BuildResult{
		ImageID:    "identifier",
		Advisories: []string{`something is horribly wrong`},
	}
	bc := sous.BuildContext{
		Source: sous.SourceContext{
			OffsetDir:      "sub",
			RemoteURL:      "github.com/opentable/test",
			Revision:       "abcd",
			NearestTagName: "2.3.7",
		},
	}
	mddf, err := ioutil.ReadAll(b.metadataDockerfile(&br, &bc))

	assert.NoError(err)
	assert.Equal(
		`FROM identifier
LABEL \
  com.opentable.sous.repo_offset="sub" \
  com.opentable.sous.repo_url="github.com/opentable/test" \
  com.opentable.sous.revision="abcd" \
  com.opentable.sous.version="2.3.7" \
  com.opentable.sous.advisories="something is horribly wrong"`, string(mddf))
}
開發者ID:opentable,項目名稱:sous,代碼行數:29,代碼來源:builder_test.go

示例11: TestNameCache

func TestNameCache(t *testing.T) {
	assert := assert.New(t)
	sous.Log.Debug.SetOutput(os.Stdout)

	ResetSingularity()
	defer ResetSingularity()

	drc := docker_registry.NewClient()
	drc.BecomeFoolishlyTrusting()

	db, err := docker.GetDatabase(&docker.DBConfig{
		Driver:     "sqlite3_sous",
		Connection: docker.InMemoryConnection("testnamecache"),
	})
	if err != nil {
		t.Fatal(err)
	}
	nc := docker.NewNameCache("", drc, db)

	repoOne := "https://github.com/opentable/one.git"
	manifest(nc, "opentable/one", "test-one", repoOne, "1.1.1")

	cn, err := nc.GetCanonicalName(BuildImageName("opentable/one", "1.1.1"))
	if err != nil {
		assert.FailNow(err.Error())
	}
	labels, err := drc.LabelsForImageName(cn)

	if assert.NoError(err) {
		assert.Equal("1.1.1", labels[docker.DockerVersionLabel])
	}
}
開發者ID:opentable,項目名稱:sous,代碼行數:32,代碼來源:name_cache_test.go

示例12: TestModifyScale

func TestModifyScale(t *testing.T) {
	log.SetFlags(log.Flags() | log.Lshortfile)
	assert := assert.New(t)
	mods := make(chan *sous.DeployablePair, 1)
	errs := make(chan error, 10)

	pair := baseDeployablePair()
	pair.Prior.Deployment.DeployConfig.NumInstances = 12
	pair.Post.Deployment.DeployConfig.NumInstances = 24

	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.Deployed, 0)
	if assert.Len(client.Created, 1) {
		assert.Equal(24, client.Created[0].Count)
	}
}
開發者ID:opentable,項目名稱:sous,代碼行數:28,代碼來源:rectifier_test.go

示例13: TestInvokeRectifyWithoutFilterFlags

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)
}
開發者ID:opentable,項目名稱:sous,代碼行數:17,代碼來源:cli_test.go

示例14: TestRoundTrip

func TestRoundTrip(t *testing.T) {
	assert := assert.New(t)
	dc := docker_registry.NewDummyClient()

	host := "docker.repo.io"
	base := "ot/wackadoo"

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

	sv := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", "1.2.3")

	in := base + ":version-1.2.3"
	digest := "sha256:012345678901234567890123456789AB012345678901234567890123456789AB"
	err := nc.Insert(sv, in, digest, []sous.Quality{})
	assert.NoError(err)

	cn, err := nc.GetCanonicalName(in)
	if assert.NoError(err) {
		assert.Equal(in, cn)
	}
	nin, _, err := nc.getImageName(sv)
	if assert.NoError(err) {
		assert.Equal(in, nin)
	}

	newSV := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", "1.2.42")

	cn = base + "@" + digest
	dc.FeedMetadata(docker_registry.Metadata{
		Registry:      host,
		Labels:        Labels(newSV),
		Etag:          digest,
		CanonicalName: cn,
		AllNames:      []string{cn, in},
	})
	sv, err = nc.GetSourceID(NewBuildArtifact(in, nil))
	if assert.Nil(err) {
		assert.Equal(newSV, sv)
	}

	ncn, err := nc.GetCanonicalName(host + "/" + in)
	if assert.Nil(err) {
		assert.Equal(host+"/"+cn, ncn)
	}
}
開發者ID:opentable,項目名稱:sous,代碼行數:45,代碼來源:image_mapping_test.go

示例15: TestGetRunningDeploymentSet_otherCluster

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()
}
開發者ID:opentable,項目名稱:sous,代碼行數:34,代碼來源:integration_test.go


注:本文中的github.com/nyarly/testify/assert.Equal函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。