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"}) }
func TestBuildDeployment(t *testing.T) { assert := assert.New(t) m := &Manifest{ Source: SourceLocation{}, Owners: []string{"*****@*****.**"}, 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) } }
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") }
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") }
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`) }
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)) }
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()) }
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") }
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) } }
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)) }
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]) } }
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) } }
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) }
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) } }
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() }
func TestModify(t *testing.T) { Log.Debug.SetOutput(os.Stderr) defer Log.Debug.SetOutput(ioutil.Discard) assert := assert.New(t) before := "1.2.3-test" after := "2.3.4-new" pair := baseDeployablePair() pair.Prior.Deployment.SourceID.Version = semv.MustParse(before) pair.Prior.Deployment.DeployConfig.NumInstances = 1 pair.Prior.Deployment.DeployConfig.Volumes = sous.Volumes{{"host", "container", "RO"}} pair.Post.Deployment.SourceID.Version = semv.MustParse(after) pair.Post.Deployment.DeployConfig.NumInstances = 24 pair.Post.Deployment.DeployConfig.Volumes = sous.Volumes{{"host", "container", "RW"}} pair.Post.BuildArtifact.Name = "2.3.4" mods := make(chan *sous.DeployablePair, 1) errs := make(chan error, 10) client := sous.NewDummyRectificationClient() deployer := NewDeployer(client) mods <- pair close(mods) deployer.RectifyModifies(mods, errs) close(errs) for e := range errs { t.Error(e) } if assert.Len(client.Created, 1) { assert.Equal(24, client.Created[0].Count) } if assert.Len(client.Deployed, 1) { assert.Regexp("2.3.4", client.Deployed[0].ImageName) log.Print(client.Deployed[0].Vols) assert.Equal("RW", string(client.Deployed[0].Vols[0].Mode)) } }
func TestRegistries(t *testing.T) { assert := assert.New(t) rs := NewRegistries() r := ®istry{} assert.NoError(rs.AddRegistry("x", r)) assert.Equal(rs.GetRegistry("x"), r) assert.NoError(rs.DeleteRegistry("x")) assert.Nil(rs.GetRegistry("x")) }
func TestRealDiff(t *testing.T) { log.SetFlags(log.Flags() | log.Lshortfile) assert := assert.New(t) intended := NewDeployments() existing := NewDeployments() repoOne := "https://github.com/opentable/one" repoTwo := "https://github.com/opentable/two" repoThree := "https://github.com/opentable/three" repoFour := "https://github.com/opentable/four" intended.MustAdd(makeDepl(repoOne, 1)) //remove existing.MustAdd(makeDepl(repoTwo, 1)) //same intended.MustAdd(makeDepl(repoTwo, 1)) //same existing.MustAdd(makeDepl(repoThree, 1)) //changed intended.MustAdd(makeDepl(repoThree, 2)) //changed existing.MustAdd(makeDepl(repoFour, 1)) //create dc := intended.Diff(existing) ds := dc.collect() if assert.Len(ds.Gone.Snapshot(), 1, "Should have one deleted item.") { it, _ := ds.Gone.Any(func(*Deployment) bool { return true }) assert.Equal(string(it.SourceID.Location.Repo), repoOne) } if assert.Len(ds.Same.Snapshot(), 1, "Should have one unchanged item.") { it, _ := ds.Same.Any(func(*Deployment) bool { return true }) assert.Equal(string(it.SourceID.Location.Repo), repoTwo) } if assert.Len(ds.Changed, 1, "Should have one modified item.") { assert.Equal(repoThree, string(ds.Changed[0].name.ManifestID.Source.Repo)) assert.Equal(repoThree, string(ds.Changed[0].Prior.SourceID.Location.Repo)) assert.Equal(repoThree, string(ds.Changed[0].Post.SourceID.Location.Repo)) assert.Equal(ds.Changed[0].Post.NumInstances, 1) assert.Equal(ds.Changed[0].Prior.NumInstances, 2) } if assert.Equal(ds.New.Len(), 1, "Should have one added item.") { it, _ := ds.New.Any(func(*Deployment) bool { return true }) assert.Equal(string(it.SourceID.Location.Repo), repoFour) } }
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") }
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`) }
func TestHandlesGDMGet(t *testing.T) { assert := assert.New(t) th := &GDMHandler{graph.CurrentGDM{ Deployments: sous.NewDeployments(), }} data, status := th.Exchange() assert.Equal(status, 200) assert.Len(data.(gdmWrapper).Deployments, 0) }
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 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 TestHarvesting(t *testing.T) { assert := assert.New(t) dc := docker_registry.NewDummyClient() host := "docker.repo.io" base := "ot/wackadoo" nc := NewNameCache(host, dc, inMemoryDB("harvesting")) v := "1.2.3" sv := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", v) v2 := "2.3.4" sisterSV := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", v2) tag := "version-1.2.3" digest := "sha256:012345678901234567890123456789AB012345678901234567890123456789AB" cn := base + "@" + digest in := base + ":" + tag dc.FeedMetadata(docker_registry.Metadata{ Registry: host, Labels: Labels(sv), Etag: digest, CanonicalName: cn, AllNames: []string{cn, in}, }) // a la a SetCollector getting the SV _, err := nc.GetSourceID(NewBuildArtifact(in, nil)) if err != nil { fmt.Printf("%+v", err) } assert.Nil(err) tag = "version-2.3.4" dc.FeedTags([]string{tag}) digest = "sha256:abcdefabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeffffffff" cn = base + "@" + digest in = base + ":" + tag dc.FeedMetadata(docker_registry.Metadata{ Registry: host, Labels: Labels(sisterSV), Etag: digest, CanonicalName: cn, AllNames: []string{cn, in}, }) nin, err := nc.GetArtifact(sisterSV) if assert.NoError(err) { assert.Equal(host+"/"+cn, nin.Name) } }
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") }
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) }
/* 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`) }
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 TestHandlesManifestGetNotKnown(t *testing.T) { assert := assert.New(t) require := require.New(t) q, err := url.ParseQuery("repo=gh") require.NoError(err) th := &GETManifestHandler{ State: sous.NewState(), QueryValues: &QueryValues{q}, } _, status := th.Exchange() assert.Equal(404, status) }
func TestBuildingRequestIDTwoClusters(t *testing.T) { cn := "test-cluster" cn2 := "test-other" url := "https://a.singularity.somewhere" clusters := make(sous.Clusters) clusters[cn] = &sous.Cluster{BaseURL: url} clusters[cn2] = &sous.Cluster{BaseURL: url} db := &deploymentBuilder{ clusters: clusters, request: &dtos.SingularityRequest{Id: "::" + cn}, req: SingReq{SourceURL: url}, } assert.NoError(t, db.assignClusterName()) assert.Equal(t, db.Target.ClusterName, cn) db2 := &deploymentBuilder{ clusters: clusters, request: &dtos.SingularityRequest{Id: "::" + cn2}, req: SingReq{SourceURL: url}, } assert.NoError(t, db2.assignClusterName()) assert.Equal(t, db2.Target.ClusterName, cn2) }