func TestReharvest(t *testing.T) { assert := assert.New(t) dc := docker_registry.NewDummyClient() _, err := dc.GetImageMetadata("", "") assert.Error(err) //because channel starved host := "docker.repo.io" base := "ot/wackadoo" nc := NewNameCache(host, dc, inMemoryDB("reharvest")) vstr := "1.2.3" sv := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", vstr) in := base + ":version-" + vstr digest := "sha256:012345678901234567890123456789AB012345678901234567890123456789AB" cn := base + "@" + digest dc.FeedMetadata(docker_registry.Metadata{ Registry: host, Labels: Labels(sv), Etag: digest, CanonicalName: cn, AllNames: []string{cn, in}, }) gotSV, err := nc.GetSourceID(NewBuildArtifact(host+"/"+in, nil)) // XXX Really prefix with host? if assert.Nil(err) { assert.Equal(gotSV, sv) } nc.dump(os.Stderr) nc.DB.Exec("update _database_metadata_ set value='' where name='fingerprint'") dc.FeedTags([]string{"version" + vstr}) dc.FeedMetadata(docker_registry.Metadata{ Registry: host, Labels: Labels(sv), Etag: digest, CanonicalName: cn, AllNames: []string{cn, in}, }) nc.dump(os.Stderr) Log.Debug.SetOutput(os.Stderr) Log.Vomit.SetOutput(os.Stderr) err = nc.GroomDatabase() assert.NoError(err) nc.dump(os.Stderr) _, err = dc.GetImageMetadata("", "") assert.Error(err) //because channel starved list, _ := dc.AllTags("") assert.Len(list, 0) //because channel starved }
func TestQueryValuesToManifestIDSadPath(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 } assert.Error(ev(manifestIDFromValues(pq("")))) assert.Error(ev(manifestIDFromValues(pq("repo=gh1&repo=gh2")))) assert.Error(ev(manifestIDFromValues(pq("repo=gh1&offset=o1&offset=o2")))) assert.Error(ev(manifestIDFromValues(pq("repo=gh1&offset=o1&flavor=f1&flavor=f2")))) }
func TestMissingName(t *testing.T) { assert := assert.New(t) dc := docker_registry.NewDummyClient() nc := NewNameCache("", dc, inMemoryDB("missing")) v := "4.5.6" sv := sous.MustNewSourceID("https://github.com/opentable/brand-new-idea", "nested/there", v) name, _, err := nc.getImageName(sv) assert.Equal("", name) assert.Error(err) }
func TestGuardImageMissing(t *testing.T) { assert := assert.New(t) svOne := MustParseSourceID(`github.com/ot/one,1.3.5`) dr := NewDummyRegistry() config := DeployConfig{NumInstances: 1} clusterX := &Cluster{Name: "x"} missing := Deployment{ClusterName: `x`, SourceID: svOne, DeployConfig: config, Cluster: clusterX} dr.FeedArtifact(nil, fmt.Errorf("dummy error")) _, err := GuardImage(dr, &missing) assert.Error(err) }
func TestMissingImage(t *testing.T) { assert := assert.New(t) clusterDefs := sous.Defs{ Clusters: sous.Clusters{ "test-cluster": &sous.Cluster{ BaseURL: SingularityURL, }, }, } repoOne := "github.com/opentable/one" drc := docker_registry.NewClient() drc.BecomeFoolishlyTrusting() // easiest way to make sure that the manifest doesn't actually get registered dummyNc := docker.NewNameCache("", drc, newInMemoryDB("bitbucket")) stateOne := sous.State{ Defs: clusterDefs, Manifests: sous.NewManifests( manifest(dummyNc, "opentable/one", "test-one", repoOne, "1.1.1"), ), } // **** nc := docker.NewNameCache("", drc, newInMemoryDB("missingimage")) client := singularity.NewRectiAgent() deployer := singularity.NewDeployer(client) r := sous.NewResolver(deployer, nc, &sous.ResolveFilter{}) deploymentsOne, err := stateOne.Deployments() if err != nil { t.Fatal(err) } err = r.Resolve(deploymentsOne, clusterDefs.Clusters) assert.Error(err) // **** time.Sleep(1 * time.Second) clusters := []string{"test-cluster"} _, which := deploymentWithRepo(clusters, nc, assert, deployer, repoOne) assert.Equal(which, none, "opentable/one was deployed") ResetSingularity() }
func TestGuardImageRejected(t *testing.T) { assert := assert.New(t) svTwo := MustParseSourceID(`github.com/ot/two,2.3.5`) dr := NewDummyRegistry() config := DeployConfig{NumInstances: 1} clusterX := &Cluster{Name: "x"} rejected := Deployment{ClusterName: `x`, SourceID: svTwo, DeployConfig: config, Cluster: clusterX} dr.FeedArtifact(&BuildArtifact{"ot-docker/one", "docker", []Quality{{"ephemeral_tag", "advisory"}}}, nil) _, err := GuardImage(dr, &rejected) assert.Error(err) }
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)) }
func TestUnpushedRevisionAdvisory(t *testing.T) { assert := assert.New(t) bc := BuildConfig{ Strict: true, Context: &BuildContext{ Sh: &shell.Sh{}, Source: SourceContext{ RevisionUnpushed: true, }, }, } ctx := bc.NewContext() assert.Contains(ctx.Advisories, string(UnpushedRev)) assert.Error(bc.GuardStrict(ctx)) }
func TestUntilReady(t *testing.T) { assert := assert.New(t) log.SetFlags(log.Flags() | log.Lshortfile) err := UntilReady(time.Second/10, time.Second, func() (string, func() bool, func()) { return "returns quickly", func() bool { return true }, func() {} }) assert.NoError(err) err = UntilReady(time.Second/10, time.Second, func() (string, func() bool, func()) { return "never returns", func() bool { return false }, func() {} }) assert.Error(err) }
func TestGitConflicts(t *testing.T) { assert := assert.New(t) require := require.New(t) gsm, dsm := setupManagers(t) actual, err := gsm.ReadState() require.NoError(err) expected := exampleState() expected.Manifests.Add(&sous.Manifest{Source: sous.SourceLocation{Repo: "github.com/opentable/brandnew"}}) dsm.WriteState(expected) expected, err = dsm.ReadState() require.NoError(err) runScript(t, `git add . git commit -m ""`, `testdata/origin`) actual.Manifests.Add(&sous.Manifest{Source: sous.SourceLocation{Repo: "github.com/opentable/newhotness"}}) assert.Error(gsm.WriteState(actual)) actual, err = gsm.ReadState() require.NoError(err) sameYAML(t, actual, expected) }
// Error asserts that a function returned an error (i.e. not `nil`). // // actualObj, err := SomeFunction() // if assert.Error(t, err, "An error was expected") { // assert.Equal(t, err, expectedError) // } // // Returns whether the assertion was successful (true) or not (false). func Error(t TestingT, err error, msgAndArgs ...interface{}) { if !assert.Error(t, err, msgAndArgs...) { t.FailNow() } }