示例#1
0
文件: testutil.go 项目: jackgr/helm
// stubContext creates a stub of a Context object.
//
// This creates a stub context with the following properties:
// - Config is initialized to empty values
// - Encoder is initialized to httputil.DefaultEncoder
// - CredentialProvider is initialized to repo.InmemCredentialProvider
// - Manager is initialized to mockManager.
func stubContext() *router.Context {
	return &router.Context{
		Config:             &router.Config{},
		Manager:            newMockManager(),
		CredentialProvider: repo.NewInmemCredentialProvider(),
		Encoder:            httputil.DefaultEncoder,
	}
}
示例#2
0
func setupDependencies(c *router.Context) error {
	var credentialProvider repo.ICredentialProvider
	if c.Config.CredentialFile != "" {
		if c.Config.CredentialSecrets {
			return errors.New("Both credentialFile and credentialSecrets are set")
		}
		var err error
		credentialProvider, err = repo.NewFilebasedCredentialProvider(c.Config.CredentialFile)
		if err != nil {
			return fmt.Errorf("cannot create credential provider %s: %s", c.Config.CredentialFile, err)
		}
	} else if *credentialSecrets {
		credentialProvider = repo.NewSecretsCredentialProvider()
	} else {
		credentialProvider = repo.NewInmemCredentialProvider()
	}
	c.CredentialProvider = credentialProvider
	c.Manager = newManager(c)

	return nil
}
示例#3
0
		for _, instance := range instances {
			d := instance.Deployment
			repository.ChartInstances[d] = append(repository.ChartInstances[d], t)
		}
	}

	return nil
}

func (repository *repositoryStub) Close() {}

var testExpander = &expanderStub{}
var testRepository = newRepositoryStub()
var testDeployer = newDeployerStub()
var testRepoService = repo.NewInmemRepoService()
var testCredentialProvider = repo.NewInmemCredentialProvider()
var testProvider = repo.NewRepoProvider(nil, repo.NewGCSRepoProvider(testCredentialProvider), testCredentialProvider)
var testManager = NewManager(testExpander, testDeployer, testRepository, testProvider, testRepoService, testCredentialProvider)

func TestListDeployments(t *testing.T) {
	testRepository.reset()
	d, err := testManager.ListDeployments()
	if err != nil {
		t.Fatalf(err.Error())
	}

	if !reflect.DeepEqual(d, deploymentList) {
		t.Fatalf("invalid deployment list")
	}
}