package tagreplication

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	"code.uber.internal/infra/kraken/core"
	"code.uber.internal/infra/kraken/utils/randutil"
	"code.uber.internal/infra/kraken/utils/testutil"
)

// StoreFixture creates a fixture of tagreplication.Store.
func StoreFixture(rv RemoteValidator) (*Store, string, func()) {
	var cleanup testutil.Cleanup
	defer cleanup.Recover()

	tmpDir, err := ioutil.TempDir(".", "test-store-")
	if err != nil {
		panic(err)
	}
	cleanup.Add(func() { os.RemoveAll(tmpDir) })

	source := filepath.Join(tmpDir, "test.db")

	store, err := NewStore(source, rv)
	if err != nil {
		panic(err)
	}
	cleanup.Add(func() { store.Close() })

	return store, source, cleanup.Run
}

// TaskFixture creates a fixture of tagreplication.Task.
func TaskFixture() *Task {
	id := randutil.Text(4)
	tag := fmt.Sprintf("prime/labrat-%s", id)
	d := core.DigestFixture()
	dest := fmt.Sprintf("build-index-%s", id)
	return NewTask(tag, d, core.DigestListFixture(3), dest)
}

package tagreplication

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	"code.uber.internal/infra/kraken/core"
	"code.uber.internal/infra/kraken/utils/randutil"
	"code.uber.internal/infra/kraken/utils/testutil"
)

// StoreFixture creates a fixture of tagreplication.Store.
func StoreFixture(rv RemoteValidator) (*Store, string, func()) {
	var cleanup testutil.Cleanup
	defer cleanup.Recover()

	tmpDir, err := ioutil.TempDir(".", "test-store-")
	if err != nil {
		panic(err)
	}
	cleanup.Add(func() { os.RemoveAll(tmpDir) })

	source := filepath.Join(tmpDir, "test.db")

	store, err := NewStore(source, rv)
	if err != nil {
		panic(err)
	}
	cleanup.Add(func() { store.Close() })

	return store, source, cleanup.Run
}

// TaskFixture creates a fixture of tagreplication.Task.
func TaskFixture() *Task {
	tag := core.TagFixture()
	d := core.DigestFixture()
	dest := fmt.Sprintf("build-index-%s", randutil.Hex(8))
	return NewTask(tag, d, core.DigestListFixture(3), dest)
}

Add origin address to build-index configuration
Add origin address to build-index configuration

Summary:
Somehow this never got populated. We now validate that the origin address is non-empty on
startup, so this was causing build-index to crash.

Reviewers: #kraken, yiran, evelynl

Reviewed By: #kraken, yiran, evelynl

Subscribers: jenkins

Differential Revision: https://code.uberinternal.com/D1823933
