Exemplo n.º 1
0
func TestErrors(t *testing.T) {
	err1 := errors.New("this is an error")
	var err2 error = nil
	assert.Err(t, err1, errors.New("this is an error"))
	assert.NoErr(t, err2)
	assert.ExistsErr(t, err1, "valid error")
}
Exemplo n.º 2
0
func TestGetRegistryDetailsGCRConfigErr(t *testing.T) {
	expectedErr := errors.New("get secret error")
	configGetter := &k8s.FakeSecret{
		FnGet: func(string) (*api.Secret, error) {
			return &api.Secret{}, expectedErr
		},
	}

	getter := &k8s.FakeSecret{
		FnGet: func(string) (*api.Secret, error) {
			return &api.Secret{}, nil
		},
	}

	kubeClient := &k8s.FakeSecretsNamespacer{
		Fn: func(namespace string) client.SecretsInterface {
			if namespace == "deis" {
				return getter
			}
			return configGetter
		},
	}

	image := "test-image"
	_, err := getRegistryDetails(kubeClient, &image, "gcr", deisNamespace, "private-registry")

	assert.Err(t, err, expectedErr)
}
Exemplo n.º 3
0
func TestWrapInLock(t *testing.T) {
	const repoName = "repo"
	lck := NewInMemoryRepositoryLock(100 * time.Second)
	assert.NoErr(t, wrapInLock(lck, repoName, func() error {
		return nil
	}))
	assert.NoErr(t, lck.Lock(repoName))
	assert.Err(t, errAlreadyLocked, wrapInLock(lck, repoName, func() error {
		return errGitReceive
	}))
	assert.Err(t, errAlreadyLocked, wrapInLock(lck, repoName, func() error {
		return nil
	}))
	assert.NoErr(t, lck.Unlock(repoName))
	assert.NoErr(t, wrapInLock(lck, repoName, func() error {
		return nil
	}))
}
Exemplo n.º 4
0
func TestGetDetailsFromDockerConfigSecretErr(t *testing.T) {
	expectedErr := errors.New("get secret error")
	getter := &k8s.FakeSecret{
		FnGet: func(string) (*api.Secret, error) {
			return &api.Secret{}, expectedErr
		},
	}
	_, err := getDetailsFromDockerConfigSecret(getter, testSecret)
	assert.Err(t, expectedErr, err)
}
Exemplo n.º 5
0
func TestCreateAppEnvConfigSecretErr(t *testing.T) {
	expectedErr := errors.New("get secret error")
	secretsClient := &k8s.FakeSecret{
		FnCreate: func(*api.Secret) (*api.Secret, error) {
			return &api.Secret{}, expectedErr
		},
	}
	err := createAppEnvConfigSecret(secretsClient, "test", nil)
	assert.Err(t, err, expectedErr)
}
Exemplo n.º 6
0
func TestWrapInLock(t *testing.T) {
	lck := NewInMemoryRepositoryLock()
	assert.NoErr(t, wrapInLock(lck, "repo", 0*time.Second, func() error {
		return nil
	}))
	lck.Lock("repo", 0*time.Second)
	assert.Err(t, errAlreadyLocked, wrapInLock(lck, "repo", 0*time.Second, func() error {
		return nil
	}))
}
Exemplo n.º 7
0
func TestObjectExistsOtherErr(t *testing.T) {
	expectedErr := errors.New("other error")
	statter := &FakeObjectStatter{
		Fn: func(context.Context, string) (storagedriver.FileInfo, error) {
			return storagedriver.FileInfoInternal{FileInfoFields: storagedriver.FileInfoFields{}}, expectedErr
		},
	}
	exists, err := ObjectExists(statter, objPath)
	assert.Err(t, err, expectedErr)
	assert.False(t, exists, "object found when the statter errored")
}
Exemplo n.º 8
0
func TestGetProcFileFromServerFailure(t *testing.T) {
	expectedErr := errors.New("test error")
	getter := &storage.FakeObjectGetter{
		Fn: func(context.Context, string) ([]byte, error) {
			return []byte("web: example-go"), expectedErr
		},
	}

	_, err := getProcFile(getter, "", objKey, buildTypeProcfile)
	assert.Err(t, err, fmt.Errorf("error in reading %s (%s)", objKey, expectedErr))
	assert.True(t, err != nil, "no error received when there should have been")
}
Exemplo n.º 9
0
func TestParse(t *testing.T) {
	//TODO: use gogenerate to generate valid html templates
	//http://godoc.org/github.com/arschles/gogenerate

	tmpl := `
    <html>
      <head>
        <title>hello {{.name}}</title>
      </head>
      <body>
        {{.greeting}}
      </body>
    </html>
  `
	fileName := "mytmpl.tmpl"
	tmplBytes := []byte(tmpl)
	expectedErr := errors.New("template not found")
	assetFunc := createValidAssetFunc(fileName, tmplBytes, expectedErr)

	tmpl1, err1 := New("test", assetFunc).Parse(fileName)
	assert.NoErr(t, err1)
	assert.False(t, tmpl1 == nil, "tmpl1 was nil when it should not have been")
	tmpl2, err2 := New("test1", assetFunc).Parse(fileName + fileName)
	assert.Err(t, err2, expectedErr)
	assert.True(t, tmpl2 == nil, "tmpl2 was not nil when it should have been")

	//TODO: check actual template output
	name := "Aaron"
	tmplData := map[string]string{
		"name": name,
	}
	buf1 := bytes.NewBuffer([]byte{})
	executeErr1 := tmpl1.Execute(buf1, tmplData)
	stdTmpl, stdTmplParseErr := template.New("referenceTest").Parse(tmpl)
	assert.NoErr(t, stdTmplParseErr)
	buf2 := bytes.NewBuffer([]byte{})
	executeErr2 := stdTmpl.Execute(buf2, tmplData)

	assert.NoErr(t, executeErr1)
	assert.NoErr(t, executeErr2)

	bytes1 := buf1.Bytes()
	bytes2 := buf2.Bytes()

	assert.True(t,
		string(bytes1) == string(bytes2),
		"actual template output %s is not equal expected %s", string(bytes1), string(bytes2))
}
Exemplo n.º 10
0
func TestHTTPDoAfterCancel(t *testing.T) {
	hndl := func(http.ResponseWriter, *http.Request) {}
	srv := testsrv.StartServer(http.HandlerFunc(hndl))
	defer srv.Close()
	transport := &http.Transport{}
	client := &http.Client{Transport: transport}
	req, err := http.NewRequest("GET", srv.URLStr(), strings.NewReader(""))
	assert.NoErr(t, err)
	ctx, cancel := context.WithCancel(context.Background())
	cancel()
	err = HTTPDo(ctx, client, transport, req, func(*http.Response, error) error {
		return nil
	})
	assert.Err(t, ErrCancelled, err)
	recv := srv.AcceptN(1, 100*time.Millisecond)
	assert.Equal(t, 0, len(recv), "number of received requests")
}
Exemplo n.º 11
0
func TestGetRegistryDetailsOffclusterErr(t *testing.T) {
	expectedErr := errors.New("get secret error")
	getter := &k8s.FakeSecret{
		FnGet: func(string) (*api.Secret, error) {
			return &api.Secret{}, expectedErr
		},
	}

	kubeClient := &k8s.FakeSecretsNamespacer{
		Fn: func(string) client.SecretsInterface {
			return getter
		},
	}
	image := "test-image"
	_, err := getRegistryDetails(kubeClient, &image, "off-cluster", deisNamespace, "private-registry")
	assert.Err(t, err, expectedErr)
}
Exemplo n.º 12
0
func TestGetRegistryDetailsGCRSecretErr(t *testing.T) {
	expectedErr := errors.New("get secret error")
	encToken := base64.StdEncoding.EncodeToString([]byte("testuser:testpassword"))
	auth := []byte(`
		{
		"auths": {
							"https://test.io": {
									"auth": "` + encToken + `",
									"email": "*****@*****.**"
							}
					}
		}
`)
	configData := make(map[string][]byte)
	configData[api.DockerConfigJsonKey] = auth
	configSecret := api.Secret{Data: configData}
	configGetter := &k8s.FakeSecret{
		FnGet: func(string) (*api.Secret, error) {
			return &configSecret, nil
		},
	}

	getter := &k8s.FakeSecret{
		FnGet: func(string) (*api.Secret, error) {
			return &api.Secret{}, expectedErr
		},
	}

	kubeClient := &k8s.FakeSecretsNamespacer{
		Fn: func(namespace string) client.SecretsInterface {
			if namespace == "deis" {
				return getter
			}
			return configGetter
		},
	}

	image := "test-image"
	_, err := getRegistryDetails(kubeClient, &image, "gcr", deisNamespace, "private-registry")

	assert.Err(t, err, expectedErr)
}
Exemplo n.º 13
0
func TestGetDetailsFromDockerConfigSecretTokenerr(t *testing.T) {
	expectedErr := errors.New("Invalid token in docker config secret")
	auth := []byte(`
    {
    "auths": {
              "https://test.io": {
                  "auth": "test",
                  "email": "*****@*****.**"
              }
          }
    }
`)
	data := make(map[string][]byte)
	data[api.DockerConfigJsonKey] = auth
	secret := api.Secret{Data: data}
	getter := &k8s.FakeSecret{
		FnGet: func(string) (*api.Secret, error) {
			return &secret, nil
		},
	}
	_, err := getDetailsFromDockerConfigSecret(getter, testSecret)
	assert.Err(t, expectedErr, err)
}