本文整理汇总了Golang中github.com/projectatomic/atomic-enterprise/test/util.Namespace函数的典型用法代码示例。如果您正苦于以下问题:Golang Namespace函数的具体用法?Golang Namespace怎么用?Golang Namespace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Namespace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestImageStreamDelete
func TestImageStreamDelete(t *testing.T) {
_, clusterAdminKubeConfig, err := testutil.StartTestMaster()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
err = testutil.CreateNamespace(clusterAdminKubeConfig, testutil.Namespace())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
stream := mockImageStream()
if err := clusterAdminClient.ImageStreams(testutil.Namespace()).Delete(stream.Name); err == nil || !errors.IsNotFound(err) {
t.Fatalf("Unxpected non-error or type: %v", err)
}
actual, err := clusterAdminClient.ImageStreams(testutil.Namespace()).Create(stream)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if err := clusterAdminClient.ImageStreams(testutil.Namespace()).Delete(actual.Name); err != nil {
t.Fatalf("Unxpected error: %v", err)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:28,代码来源:imagestream_test.go
示例2: TestTriggers_manual
func TestTriggers_manual(t *testing.T) {
testutil.DeleteAllEtcdKeys()
openshift := NewTestDeployOpenshift(t)
defer openshift.Close()
config := deploytest.OkDeploymentConfig(0)
config.Namespace = testutil.Namespace()
config.Triggers = []deployapi.DeploymentTriggerPolicy{
{
Type: deployapi.DeploymentTriggerManual,
},
}
var err error
dc, err := openshift.Client.DeploymentConfigs(testutil.Namespace()).Create(config)
if err != nil {
t.Fatalf("Couldn't create DeploymentConfig: %v %#v", err, config)
}
watch, err := openshift.KubeClient.ReplicationControllers(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), dc.ResourceVersion)
if err != nil {
t.Fatalf("Couldn't subscribe to Deployments: %v", err)
}
defer watch.Stop()
config, err = openshift.Client.DeploymentConfigs(testutil.Namespace()).Generate(config.Name)
if err != nil {
t.Fatalf("Error generating config: %v", err)
}
if config.LatestVersion != 1 {
t.Fatalf("Generated deployment should have version 1: %#v", config)
}
glog.Infof("config(1): %#v", config)
new, err := openshift.Client.DeploymentConfigs(testutil.Namespace()).Update(config)
if err != nil {
t.Fatalf("Couldn't create updated DeploymentConfig: %v %#v", err, config)
}
glog.Infof("config(2): %#v", new)
event := <-watch.ResultChan()
if e, a := watchapi.Added, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
deployment := event.Object.(*kapi.ReplicationController)
if e, a := config.Name, deployutil.DeploymentConfigNameFor(deployment); e != a {
t.Fatalf("Expected deployment annotated with deploymentConfig '%s', got '%s'", e, a)
}
if e, a := 1, deployutil.DeploymentVersionFor(deployment); e != a {
t.Fatalf("Deployment annotation version does not match: %#v", deployment)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:54,代码来源:deploy_trigger_test.go
示例3: runBuildRunningPodDeleteTest
func runBuildRunningPodDeleteTest(t *testing.T, clusterAdminClient *client.Client, clusterAdminKubeClient *kclient.Client) {
buildWatch, err := clusterAdminClient.Builds(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), "0")
if err != nil {
t.Fatalf("Couldn't subscribe to Builds %v", err)
}
defer buildWatch.Stop()
created, err := clusterAdminClient.Builds(testutil.Namespace()).Create(mockBuild())
if err != nil {
t.Fatalf("Couldn't create Build: %v", err)
}
podWatch, err := clusterAdminKubeClient.Pods(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), created.ResourceVersion)
if err != nil {
t.Fatalf("Couldn't subscribe to Pods %v", err)
}
defer podWatch.Stop()
// wait for initial build event from the creation of the imagerepo with tag latest
event := waitForWatch(t, "initial build added", buildWatch)
if e, a := watchapi.Added, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
newBuild := event.Object.(*buildapi.Build)
// initial pod creation for build
event = waitForWatch(t, "build pod created", podWatch)
if e, a := watchapi.Added, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
event = waitForWatch(t, "build updated to pending", buildWatch)
if e, a := watchapi.Modified, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
newBuild = event.Object.(*buildapi.Build)
if newBuild.Status != buildapi.BuildStatusPending {
t.Fatalf("expected build status to be marked pending, but was marked %s", newBuild.Status)
}
clusterAdminKubeClient.Pods(testutil.Namespace()).Delete(buildutil.GetBuildPodName(newBuild), kapi.NewDeleteOptions(0))
event = waitForWatch(t, "build updated to error", buildWatch)
if e, a := watchapi.Modified, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
newBuild = event.Object.(*buildapi.Build)
if newBuild.Status != buildapi.BuildStatusError {
t.Fatalf("expected build status to be marked error, but was marked %s", newBuild.Status)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:51,代码来源:buildcontroller_test.go
示例4: TestDeleteBuildConfig
func TestDeleteBuildConfig(t *testing.T) {
testutil.DeleteAllEtcdKeys()
openshift := NewTestBuildOpenshift(t)
defer openshift.Close()
buildConfig := mockBuildConfig()
actual, err := openshift.Client.BuildConfigs(testutil.Namespace()).Create(buildConfig)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if err := openshift.Client.BuildConfigs(testutil.Namespace()).Delete(actual.Name); err != nil {
t.Fatalf("Unxpected error: %v", err)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:14,代码来源:buildcfgclient_test.go
示例5: imageChangeBuildConfig
func imageChangeBuildConfig(name string, strategy buildapi.BuildStrategy) *buildapi.BuildConfig {
return &buildapi.BuildConfig{
ObjectMeta: kapi.ObjectMeta{
Name: name,
Namespace: testutil.Namespace(),
Labels: map[string]string{"testlabel": "testvalue"},
},
Parameters: buildapi.BuildParameters{
Source: buildapi.BuildSource{
Type: "Git",
Git: &buildapi.GitBuildSource{
URI: "git://github.com/openshift/ruby-hello-world.git",
},
ContextDir: "contextimage",
},
Strategy: strategy,
Output: buildapi.BuildOutput{
To: &kapi.ObjectReference{
Name: "test-image-trigger-repo",
},
Tag: "outputtag",
},
},
Triggers: []buildapi.BuildTriggerPolicy{
{
Type: buildapi.ImageChangeBuildTriggerType,
ImageChange: &buildapi.ImageChangeTrigger{},
},
},
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:31,代码来源:imagechange_buildtrigger_test.go
示例6: TestImageStreamCreate
func TestImageStreamCreate(t *testing.T) {
_, clusterAdminKubeConfig, err := testutil.StartTestMaster()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
err = testutil.CreateNamespace(clusterAdminKubeConfig, testutil.Namespace())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
stream := mockImageStream()
if _, err := clusterAdminClient.ImageStreams(testutil.Namespace()).Create(&imageapi.ImageStream{}); err == nil || !errors.IsInvalid(err) {
t.Fatalf("Unexpected error: %v", err)
}
expected, err := clusterAdminClient.ImageStreams(testutil.Namespace()).Create(stream)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if expected.Name == "" {
t.Errorf("Unexpected empty image Name %v", expected)
}
actual, err := clusterAdminClient.ImageStreams(testutil.Namespace()).Get(stream.Name)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %s", util.ObjectDiff(expected, actual))
}
streams, err := clusterAdminClient.ImageStreams(testutil.Namespace()).List(labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
if len(streams.Items) != 1 {
t.Errorf("Expected one image, got %#v", streams.Items)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:45,代码来源:imagestream_test.go
示例7: runBuildDeleteTest
func runBuildDeleteTest(t *testing.T, clusterAdminClient *client.Client, clusterAdminKubeClient *kclient.Client) {
buildWatch, err := clusterAdminClient.Builds(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), "0")
if err != nil {
t.Fatalf("Couldn't subscribe to Builds %v", err)
}
defer buildWatch.Stop()
created, err := clusterAdminClient.Builds(testutil.Namespace()).Create(mockBuild())
if err != nil {
t.Fatalf("Couldn't create Build: %v", err)
}
podWatch, err := clusterAdminKubeClient.Pods(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), created.ResourceVersion)
if err != nil {
t.Fatalf("Couldn't subscribe to Pods %v", err)
}
defer podWatch.Stop()
// wait for initial build event from the creation of the imagerepo with tag latest
event := waitForWatch(t, "initial build added", buildWatch)
if e, a := watchapi.Added, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
newBuild := event.Object.(*buildapi.Build)
// initial pod creation for build
event = waitForWatch(t, "build pod created", podWatch)
if e, a := watchapi.Added, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
clusterAdminClient.Builds(testutil.Namespace()).Delete(newBuild.Name)
event = waitForWatch(t, "pod deleted due to build deleted", podWatch)
if e, a := watchapi.Deleted, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
pod := event.Object.(*kapi.Pod)
if expected := buildutil.GetBuildPodName(newBuild); pod.Name != expected {
t.Fatalf("Expected pod %s to be deleted, but pod %s was deleted", expected, pod.Name)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:44,代码来源:buildcontroller_test.go
示例8: putManifest
func putManifest(name, user, token string) (digest.Digest, error) {
putUrl := fmt.Sprintf("http://127.0.0.1:5000/v2/%s/%s/manifests/%s", testutil.Namespace(), name, imageapi.DefaultImageTag)
signedManifest, dgst, err := signedManifest(fmt.Sprintf("%s/%s", testutil.Namespace(), name))
if err != nil {
return "", err
}
req, err := http.NewRequest("PUT", putUrl, bytes.NewReader(signedManifest))
if err != nil {
return "", fmt.Errorf("error creating put request: %s", err)
}
req.SetBasicAuth(user, token)
client := http.DefaultClient
resp, err := client.Do(req)
if err != nil {
return "", fmt.Errorf("error putting manifest: %s", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusAccepted {
return "", fmt.Errorf("unexpected put status code: %d", resp.StatusCode)
}
return dgst, nil
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:22,代码来源:v2_docker_registry_test.go
示例9: TestCreateBuildConfig
func TestCreateBuildConfig(t *testing.T) {
testutil.DeleteAllEtcdKeys()
openshift := NewTestBuildOpenshift(t)
defer openshift.Close()
buildConfig := mockBuildConfig()
expected, err := openshift.Client.BuildConfigs(testutil.Namespace()).Create(buildConfig)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if expected.Name == "" {
t.Errorf("Unexpected empty buildConfig ID %v", expected)
}
buildConfigs, err := openshift.Client.BuildConfigs(testutil.Namespace()).List(labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
if len(buildConfigs.Items) != 1 {
t.Errorf("Expected one buildConfig, got %#v", buildConfigs.Items)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:22,代码来源:buildcfgclient_test.go
示例10: TestListBuildConfigs
func TestListBuildConfigs(t *testing.T) {
testutil.DeleteAllEtcdKeys()
openshift := NewTestBuildOpenshift(t)
defer openshift.Close()
buildConfigs, err := openshift.Client.BuildConfigs(testutil.Namespace()).List(labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
if len(buildConfigs.Items) != 0 {
t.Errorf("Expected no buildConfigs, got %#v", buildConfigs.Items)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:13,代码来源:buildcfgclient_test.go
示例11: TestWebhookGitHubPing
func TestWebhookGitHubPing(t *testing.T) {
testutil.DeleteAllEtcdKeys()
openshift := NewTestBuildOpenshift(t)
defer openshift.Close()
openshift.KubeClient.Namespaces().Create(&kapi.Namespace{
ObjectMeta: kapi.ObjectMeta{Name: testutil.Namespace()},
})
// create buildconfig
buildConfig := mockBuildConfigImageParms("originalImage", "imageStream", "validTag")
if _, err := openshift.Client.BuildConfigs(testutil.Namespace()).Create(buildConfig); err != nil {
t.Fatalf("Unexpected error: %v", err)
}
watch, err := openshift.Client.Builds(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), "0")
if err != nil {
t.Fatalf("Couldn't subscribe to builds: %v", err)
}
defer watch.Stop()
for _, s := range []string{
"/oapi/v1/namespaces/" + testutil.Namespace() + "/buildconfigs/pushbuild/webhooks/secret101/github",
} {
// trigger build event sending push notification
postFile(&http.Client{}, "ping", "pingevent.json", openshift.server.URL+s, http.StatusOK, t)
// TODO: improve negative testing
timer := time.NewTimer(time.Second / 2)
select {
case <-timer.C:
// nothing should happen
case event := <-watch.ResultChan():
build := event.Object.(*buildapi.Build)
t.Fatalf("Unexpected build created: %#v", build)
}
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:38,代码来源:webhookgithub_test.go
示例12: TestImageStreamList
func TestImageStreamList(t *testing.T) {
_, clusterAdminKubeConfig, err := testutil.StartTestMaster()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
err = testutil.CreateNamespace(clusterAdminKubeConfig, testutil.Namespace())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
builds, err := clusterAdminClient.ImageStreams(testutil.Namespace()).List(labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
if len(builds.Items) != 0 {
t.Errorf("Expected no builds, got %#v", builds.Items)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:23,代码来源:imagestream_test.go
示例13: setupBuildControllerTest
func setupBuildControllerTest(additionalBuildControllers, additionalBuildPodControllers, additionalImageChangeControllers int, t *testing.T) (*client.Client, *kclient.Client) {
master, clusterAdminKubeConfig, err := testutil.StartTestMaster()
checkErr(t, err)
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
checkErr(t, err)
clusterAdminKubeClient, err := testutil.GetClusterAdminKubeClient(clusterAdminKubeConfig)
checkErr(t, err)
_, err = clusterAdminKubeClient.Namespaces().Create(&kapi.Namespace{
ObjectMeta: kapi.ObjectMeta{Name: testutil.Namespace()},
})
checkErr(t, err)
if err := testutil.WaitForServiceAccounts(clusterAdminKubeClient, testutil.Namespace(), []string{bootstrappolicy.BuilderServiceAccountName, bootstrappolicy.DefaultServiceAccountName}); err != nil {
t.Errorf("unexpected error: %v", err)
}
openshiftConfig, err := origin.BuildMasterConfig(*master)
checkErr(t, err)
// Get the build controller clients, since those rely on service account tokens
// We don't want to proceed with the rest of the test until those are available
openshiftConfig.BuildControllerClients()
for i := 0; i < additionalBuildControllers; i++ {
openshiftConfig.RunBuildController()
}
for i := 0; i < additionalBuildPodControllers; i++ {
openshiftConfig.RunBuildPodController()
}
for i := 0; i < additionalImageChangeControllers; i++ {
openshiftConfig.RunBuildImageChangeTriggerController()
}
return clusterAdminClient, clusterAdminKubeClient
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:36,代码来源:buildcontroller_test.go
示例14: TestWatchBuildConfigs
func TestWatchBuildConfigs(t *testing.T) {
testutil.DeleteAllEtcdKeys()
openshift := NewTestBuildOpenshift(t)
defer openshift.Close()
buildConfig := mockBuildConfig()
watch, err := openshift.Client.BuildConfigs(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), "0")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
defer watch.Stop()
expected, err := openshift.Client.BuildConfigs(testutil.Namespace()).Create(buildConfig)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
event := <-watch.ResultChan()
actual := event.Object.(*buildapi.BuildConfig)
if e, a := expected.Name, actual.Name; e != a {
t.Errorf("Expected buildConfig Name %s, got %s", e, a)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:24,代码来源:buildcfgclient_test.go
示例15: setup
func setup(t *testing.T) *client.Client {
_, clusterAdminKubeConfig, err := testutil.StartTestMaster()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminKubeClient, err := testutil.GetClusterAdminKubeClient(clusterAdminKubeConfig)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminKubeClient.Namespaces().Create(&kapi.Namespace{
ObjectMeta: kapi.ObjectMeta{Name: testutil.Namespace()},
})
return clusterAdminClient
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:20,代码来源:imagechange_buildtrigger_test.go
示例16: getTags
func getTags(streamName, user, token string) ([]string, error) {
url := fmt.Sprintf("http://127.0.0.1:5000/v2/%s/%s/tags/list", testutil.Namespace(), streamName)
client := http.DefaultClient
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return []string{}, fmt.Errorf("error creating request: %v", err)
}
req.SetBasicAuth(user, token)
resp, err := client.Do(req)
if err != nil {
return []string{}, fmt.Errorf("error retrieving tags from registry: %s", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return []string{}, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
m := make(map[string]interface{})
err = json.Unmarshal(body, &m)
if err != nil {
return []string{}, fmt.Errorf("error unmarhsaling response %q: %s", body, err)
}
arr, ok := m["tags"].([]interface{})
if !ok {
return []string{}, fmt.Errorf("couldn't convert tags")
}
tags := []string{}
for _, value := range arr {
tag, ok := value.(string)
if !ok {
return []string{}, fmt.Errorf("tag %#v is not a string", value)
}
tags = append(tags, tag)
}
return tags, nil
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:36,代码来源:v2_docker_registry_test.go
示例17: TestImageStreamMappingCreate
func TestImageStreamMappingCreate(t *testing.T) {
_, clusterAdminKubeConfig, err := testutil.StartTestMaster()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
err = testutil.CreateNamespace(clusterAdminKubeConfig, testutil.Namespace())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
stream := mockImageStream()
expected, err := clusterAdminClient.ImageStreams(testutil.Namespace()).Create(stream)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if expected.Name == "" {
t.Errorf("Unexpected empty image Name %v", expected)
}
// create a mapping to an image that doesn't exist
mapping := &imageapi.ImageStreamMapping{
ObjectMeta: kapi.ObjectMeta{Name: stream.Name},
Tag: "newer",
Image: imageapi.Image{
ObjectMeta: kapi.ObjectMeta{
Name: "image1",
},
DockerImageReference: "some/other/name",
},
}
if err := clusterAdminClient.ImageStreamMappings(testutil.Namespace()).Create(mapping); err != nil {
t.Fatalf("unexpected error: %v", err)
}
// verify we can tag a second time with the same data, and nothing changes
if err := clusterAdminClient.ImageStreamMappings(testutil.Namespace()).Create(mapping); err != nil {
t.Fatalf("unexpected non-error or type: %v", err)
}
// create an image directly
image := &imageapi.Image{
ObjectMeta: kapi.ObjectMeta{Name: "image2"},
DockerImageMetadata: imageapi.DockerImage{
Config: imageapi.DockerConfig{
Env: []string{"A=B"},
},
},
}
if _, err := clusterAdminClient.Images().Create(image); err == nil {
t.Error("unexpected non-error")
}
image.DockerImageReference = "some/other/name" // can reuse references across multiple images
actual, err := clusterAdminClient.Images().Create(image)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if actual == nil || actual.Name != image.Name {
t.Errorf("unexpected object: %#v", actual)
}
// verify that image stream mappings cannot mutate / overwrite the image (images are immutable)
mapping = &imageapi.ImageStreamMapping{
ObjectMeta: kapi.ObjectMeta{Name: stream.Name},
Tag: "newest",
Image: *image,
}
mapping.Image.DockerImageReference = "different"
if err := clusterAdminClient.ImageStreamMappings(testutil.Namespace()).Create(mapping); err != nil {
t.Fatalf("unexpected error: %v", err)
}
image, err = clusterAdminClient.Images().Get(image.Name)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if image.DockerImageReference != "some/other/name" {
t.Fatalf("image was unexpectedly mutated: %#v", image)
}
// ensure the correct tags are set
updated, err := clusterAdminClient.ImageStreams(testutil.Namespace()).Get(stream.Name)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if updated.Spec.Tags != nil && len(updated.Spec.Tags) > 0 {
t.Errorf("unexpected object: %#v", updated.Spec.Tags)
}
fromTag, err := clusterAdminClient.ImageStreamTags(testutil.Namespace()).Get(stream.Name, "newer")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if fromTag.Name != "test:newer" || fromTag.Image.UID == "" || fromTag.Image.DockerImageReference != "some/other/name" {
t.Errorf("unexpected object: %#v", fromTag)
}
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:101,代码来源:imagestream_test.go
示例18: TestTriggers_configChange
func TestTriggers_configChange(t *testing.T) {
testutil.DeleteAllEtcdKeys()
openshift := NewTestDeployOpenshift(t)
defer openshift.Close()
config := deploytest.OkDeploymentConfig(0)
config.Namespace = testutil.Namespace()
config.Triggers[0] = deploytest.OkConfigChangeTrigger()
var err error
watch, err := openshift.KubeClient.ReplicationControllers(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), "0")
if err != nil {
t.Fatalf("Couldn't subscribe to Deployments %v", err)
}
defer watch.Stop()
// submit the initial deployment config
if _, err := openshift.Client.DeploymentConfigs(testutil.Namespace()).Create(config); err != nil {
t.Fatalf("Couldn't create DeploymentConfig: %v", err)
}
// verify the initial deployment exists
event := <-watch.ResultChan()
if e, a := watchapi.Added, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
deployment := event.Object.(*kapi.ReplicationController)
if e, a := config.Name, deployutil.DeploymentConfigNameFor(deployment); e != a {
t.Fatalf("Expected deployment annotated with deploymentConfig '%s', got '%s'", e, a)
}
assertEnvVarEquals("ENV1", "VAL1", deployment, t)
// submit a new config with an updated environment variable
if config, err = openshift.Client.DeploymentConfigs(testutil.Namespace()).Generate(config.Name); err != nil {
t.Fatalf("Error generating config: %v", err)
}
config.Template.ControllerTemplate.Template.Spec.Containers[0].Env[0].Value = "UPDATED"
// before we update the config, we need to update the state of the existing deployment
// this is required to be done manually since the deployment and deployer pod controllers are not run in this test
deployment.Annotations[deployapi.DeploymentStatusAnnotation] = string(deployapi.DeploymentStatusComplete)
// update the deployment
if _, err = openshift.KubeClient.ReplicationControllers(testutil.Namespace()).Update(deployment); err != nil {
t.Fatalf("Error updating existing deployment: %v", err)
}
event = <-watch.ResultChan()
if e, a := watchapi.Modified, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
if _, err := openshift.Client.DeploymentConfigs(testutil.Namespace()).Update(config); err != nil {
t.Fatalf("Couldn't create updated DeploymentConfig: %v", err)
}
event = <-watch.ResultChan()
if e, a := watchapi.Added, event.Type; e != a {
t.Fatalf("expected watch event type %s, got %s", e, a)
}
newDeployment := event.Object.(*kapi.ReplicationController)
assertEnvVarEquals("ENV1", "UPDATED", newDeployment, t)
if newDeployment.Name == deployment.Name {
t.Fatalf("expected new deployment; old=%s, new=%s", deployment.Name, newDeployment.Name)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:71,代码来源:deploy_trigger_test.go
示例19: TestTriggers_imageChange
func TestTriggers_imageChange(t *testing.T) {
_, clusterAdminKubeConfig, err := testutil.StartTestMaster()
if err != nil {
t.Fatalf("error starting master: %v", err)
}
openshiftClusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Fatalf("error getting OpenShift cluster admin client: %v", err)
}
openshiftClusterAdminClientConfig, err := testutil.GetClusterAdminClientConfig(clusterAdminKubeConfig)
if err != nil {
t.Fatalf("error getting cluster admin client config: %v", err)
}
openshiftProjectAdminClient, err := testutil.CreateNewProject(openshiftClusterAdminClient, *openshiftClusterAdminClientConfig, testutil.Namespace(), "bob")
if err != nil {
t.Fatalf("error creating project: %v", err)
}
imageStream := &imageapi.ImageStream{ObjectMeta: kapi.ObjectMeta{Name: "test-image-stream"}}
config := deploytest.OkDeploymentConfig(0)
config.Namespace = testutil.Namespace()
configWatch, err := openshiftProjectAdminClient.DeploymentConfigs(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), "0")
if err != nil {
t.Fatalf("Couldn't subscribe to Deployments %v", err)
}
defer configWatch.Stop()
if imageStream, err = openshiftProjectAdminClient.ImageStreams(testutil.Namespace()).Create(imageStream); err != nil {
t.Fatalf("Couldn't create ImageStream: %v", err)
}
imageWatch, err := openshiftProjectAdminClient.ImageStreams(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), "0")
if err != nil {
t.Fatalf("Couldn't subscribe to ImageStreams: %s", err)
}
defer imageWatch.Stop()
// Make a function which can create a new tag event for the image stream and
// then wait for the stream status to be asynchronously updated.
createTagEvent := func(image string) {
mapping := &imageapi.ImageStreamMapping{
ObjectMeta: kapi.ObjectMeta{Name: imageStream.Name},
Tag: "latest",
Image: imageapi.Image{
ObjectMeta: kapi.ObjectMeta{
Name: image,
},
DockerImageReference: fmt.Sprintf("registry:8080/openshift/[email protected]%s", image),
},
}
if err := openshiftProjectAdminClient.ImageStreamMappings(testutil.Namespace()).Create(mapping); err != nil {
t.Fatalf("unexpected error: %v", err)
}
t.Log("Waiting for image stream mapping to be reflected in the IS status...")
statusLoop:
for {
select {
case event := <-imageWatch.ResultChan():
stream := event.Object.(*imageapi.ImageStream)
if _, ok := stream.Status.Tags["latest"]; ok {
t.Logf("ImageStream %s now has Status with tags: %#v", stream.Name, stream.Status.Tags)
break statusLoop
} else {
t.Logf("Still waiting for latest tag status on ImageStream %s", stream.Name)
}
}
}
}
if config, err = openshiftProjectAdminClient.DeploymentConfigs(testutil.Namespace()).Create(config); err != nil {
t.Fatalf("Couldn't create DeploymentConfig: %v", err)
}
createTagEvent("sha256:00000000000000000000000000000001")
var newConfig *deployapi.DeploymentConfig
t.Log("Waiting for a new deployment config in response to ImageStream update")
waitForNewConfig:
for {
select {
case event := <-configWatch.ResultChan():
if event.Type == watchapi.Modified {
newConfig = event.Object.(*deployapi.DeploymentConfig)
break waitForNewConfig
}
}
}
if e, a := 1, newConfig.LatestVersion; e != a {
t.Fatalf("expected config version %d, got %d", e, a)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:95,代码来源:deploy_trigger_test.go
示例20: TestV2RegistryGetTags
func TestV2RegistryGetTags(t *testing.T) {
_, clusterAdminKubeConfig, err := testutil.StartTestMaster()
if err != nil {
t.Fatalf("error starting master: %v", err)
}
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Fatalf("error getting cluster admin client: %v", err)
}
clusterAdminClientConfig, err := testutil.GetClusterAdminClientConfig(clusterAdminKubeConfig)
if err != nil {
t.Fatalf("error getting cluster admin client config: %v", err)
}
user := "admin"
adminClient, err := testutil.CreateNewProject(clusterAdminClient, *clusterAdminClientConfig, testutil.Namespace(), user)
if err != nil {
t.Fatalf("error creating project: %v", err)
}
token, err := tokencmd.RequestToken(clusterAdminClientConfig, nil, user, "password")
if err != nil {
t.Fatalf("error requesting token: %v", err)
}
config := `version: 0.1
loglevel: debug
http:
addr: 127.0.0.1:5000
storage:
inmemory: {}
auth:
openshift:
middleware:
repository:
- name: openshift
`
os.Setenv("OPENSHIFT_CA_DATA", string(clusterAdminClientConfig.CAData))
os.Setenv("OPENSHIFT_CERT_DATA", string(clusterAdminClientConfig.CertData))
os.Setenv("OPENSHIFT_KEY_DATA", string(clusterAdminClientConfig.KeyData))
os.Setenv("OPENSHIFT_MASTER", clusterAdminClientConfig.Host)
os.Setenv("REGISTRY_URL", "127.0.0.1:5000")
go dockerregistry.Execute(strings.NewReader(config))
stream := imageapi.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Namespace: testutil.Namespace(),
Name: "test",
},
}
if _, err := adminClient.ImageStreams(testutil.Namespace()).Create(&stream); err != nil {
t.Fatalf("error creating image stream: %s", err)
}
tags, err := getTags(stream.Name, user, token)
if err != nil {
t.Fatal(err)
}
if len(tags) > 0 {
t.Fatalf("expected 0 tags, got: %#v", tags)
}
dgst, err := putManifest(stream.Name, user, token)
if err != nil {
t.Fatal(err)
}
tags, err = getTags(stream.Name, user, token)
if err != nil {
t.Fatal(err)
}
if len(tags) != 1 {
t.Fatalf("expected 1 tag, got %d: %v", len(tags), tags)
}
if tags[0] != imageapi.DefaultImageTag {
t.Fatalf("expected latest, got %q", tags[0])
}
// test get by tag
url := fmt.Sprintf("http://127.0.0.1:5000/v2/%s/%s/manifests/%s", testutil.Namespace(), stream.Name, imageapi.DefaultImageTag)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatalf("error creating request: %v", err)
}
req.SetBasicAuth(user, token)
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("error retrieving manifest from registry: %s", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Fatalf("unexpected status code: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
var retrievedManifest manifest.Manifest
if err := json.Unmarshal(body, &retrievedManifest); err != nil {
t.Fatalf("error unmarshaling retrieved manifest")
}
if retrievedManifest.Name != fmt.Sprintf("%s/%s", testutil.Namespace(), stream.Name) {
t.Fatalf("unexpected manifest name: %s", retrievedManifest.Name)
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:101,代码来源:v2_docker_registry_test.go
注:本文中的github.com/projectatomic/atomic-enterprise/test/util.Namespace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论