示例#1
0
func TestEnvironmentResolve(t *testing.T) {
	factory := &TestServiceFactory{
		Counts: map[string]int{},
	}

	p := NewProject(&Context{
		ServiceFactory:    factory,
		EnvironmentLookup: &TestEnvironmentLookup{},
	})
	p.Configs = config.NewConfigs()
	p.Configs.Add("foo", &config.ServiceConfig{
		Environment: yaml.MaporEqualSlice([]string{
			"A",
			"A=",
			"A=B",
		}),
	})

	service, err := p.CreateService("foo")
	if err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(service.Config().Environment, yaml.MaporEqualSlice{"A=X", "A=X", "A=B"}) {
		t.Fatal("Invalid environment", service.Config().Environment)
	}
}
示例#2
0
// NewProject creates a new project with the specified context.
func NewProject(context *Context) *Project {
	p := &Project{
		context: context,
		Configs: config.NewConfigs(),
	}

	if context.LoggerFactory == nil {
		context.LoggerFactory = &logger.NullLogger{}
	}

	context.Project = p

	p.listeners = []chan<- Event{NewDefaultListener(p)}

	return p
}
示例#3
0
func TestTwoCall(t *testing.T) {
	factory := &TestServiceFactory{
		Counts: map[string]int{},
	}

	p := NewProject(&Context{
		ServiceFactory: factory,
	})
	p.Configs = config.NewConfigs()
	p.Configs.Add("foo", &config.ServiceConfig{})

	if err := p.Create("foo"); err != nil {
		t.Fatal(err)
	}

	if err := p.Create("foo"); err != nil {
		t.Fatal(err)
	}

	if factory.Counts["foo.create"] != 2 {
		t.Fatal("Failed to create twice")
	}
}