manifest becomes kustomization

This commit is contained in:
Jeffrey Regan
2018-04-12 13:31:52 -07:00
parent 5c684d789c
commit 8f0a04c84d
32 changed files with 289 additions and 287 deletions

View File

@@ -19,10 +19,10 @@ package error
import "fmt"
type ConfigmapError struct {
ManifestFilepath string
ErrorMsg string
Path string
ErrorMsg string
}
func (e ConfigmapError) Error() string {
return fmt.Sprintf("Manifest file [%s] encounters a configmap error: %s\n", e.ManifestFilepath, e.ErrorMsg)
return fmt.Sprintf("Kustomization file [%s] encounters a configmap error: %s\n", e.Path, e.ErrorMsg)
}

View File

@@ -24,7 +24,7 @@ import (
func TestConfigmapError_Error(t *testing.T) {
filepath := "/path/to/kustomize.yaml"
errorMsg := "configmap name is missing"
me := ConfigmapError{ManifestFilepath: filepath, ErrorMsg: errorMsg}
me := ConfigmapError{Path: filepath, ErrorMsg: errorMsg}
if !strings.Contains(me.Error(), filepath) {
t.Errorf("Incorrect ConfigmapError.Error() message \n")

View File

@@ -21,37 +21,37 @@ import (
)
// First pass to encapsulate fields for more informative error messages.
type ManifestError struct {
ManifestFilepath string
ErrorMsg string
type KustomizationError struct {
KustomizationPath string
ErrorMsg string
}
func (me ManifestError) Error() string {
return fmt.Sprintf("Manifest File [%s]: %s\n", me.ManifestFilepath, me.ErrorMsg)
func (ke KustomizationError) Error() string {
return fmt.Sprintf("Kustomization File [%s]: %s\n", ke.KustomizationPath, ke.ErrorMsg)
}
type ManifestErrors struct {
merrors []error
type KustomizationErrors struct {
kErrors []error
}
func (me *ManifestErrors) Error() string {
func (ke *KustomizationErrors) Error() string {
errormsg := ""
for _, e := range me.merrors {
for _, e := range ke.kErrors {
errormsg += e.Error() + "\n"
}
return errormsg
}
func (me *ManifestErrors) Append(e error) {
me.merrors = append(me.merrors, e)
func (ke *KustomizationErrors) Append(e error) {
ke.kErrors = append(ke.kErrors, e)
}
func (me *ManifestErrors) Get() []error {
return me.merrors
func (ke *KustomizationErrors) Get() []error {
return ke.kErrors
}
func (me *ManifestErrors) BatchAppend(e ManifestErrors) {
func (ke *KustomizationErrors) BatchAppend(e KustomizationErrors) {
for _, err := range e.Get() {
me.merrors = append(me.merrors, err)
ke.kErrors = append(ke.kErrors, err)
}
}

View File

@@ -0,0 +1,92 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package error
import (
"fmt"
"strings"
"testing"
)
func TestKustomizationError_Error(t *testing.T) {
filepath := "/path/to/kustomize.yaml"
errorMsg := "Kustomization not found"
me := KustomizationError{KustomizationPath: filepath, ErrorMsg: errorMsg}
if !strings.Contains(me.Error(), filepath) {
t.Errorf("Incorrect KustomizationError.Error() message \n")
t.Errorf("Expected filepath %s, but unfound\n", filepath)
}
if !strings.Contains(me.Error(), errorMsg) {
t.Errorf("Incorrect KustomizationError.Error() message \n")
t.Errorf("Expected errorMsg %s, but unfound\n", errorMsg)
}
}
func TestKustomizationErrors_Error(t *testing.T) {
filepath := "/path/to/kustomize"
me := KustomizationError{KustomizationPath: filepath, ErrorMsg: "Kustomization not found"}
ce := ConfigmapError{Path: filepath, ErrorMsg: "can't find configmap name"}
pe := PatchError{KustomizationPath: filepath, PatchFilepath: filepath, ErrorMsg: "can't find patch file"}
re := ResourceError{KustomizationPath: filepath, ResourceFilepath: filepath, ErrorMsg: "can't find resource file"}
se := SecretError{KustomizationPath: filepath, ErrorMsg: "can't find secret name"}
mes := KustomizationErrors{kErrors: []error{me, ce, pe, re, se}}
expectedErrorMsg := fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n", me.Error(), ce.Error(), pe.Error(), re.Error(), se.Error())
if mes.Error() != expectedErrorMsg {
t.Errorf("Incorrect KustomizationErrors.Error() message\n")
t.Errorf(" Expected: %s\n", expectedErrorMsg)
t.Errorf(" Got: %s\n", mes.Error())
}
}
func TestKustomizationErrors_Get(t *testing.T) {
ce := ConfigmapError{Path: "kustomization/filepath", ErrorMsg: "can't find configmap name"}
mes := KustomizationErrors{kErrors: []error{ce}}
if len(mes.Get()) != 1 {
t.Errorf("Incorrect KustomizationErrors.Get()\n")
t.Errorf(" Expected: %v\n", []error{ce})
t.Errorf(" Got: %s\n", mes.Get())
}
}
func TestKustomizationErrors_Append(t *testing.T) {
ce := ConfigmapError{Path: "kustomization/filepath", ErrorMsg: "can't find configmap name"}
pe := PatchError{KustomizationPath: "kustomization/filepath", PatchFilepath: "patch/path", ErrorMsg: "can't find patch file"}
mes := KustomizationErrors{kErrors: []error{ce}}
mes.Append(pe)
if len(mes.Get()) != 2 {
t.Errorf("Incorrect KustomizationErrors.Append()\n")
t.Errorf(" Expected: %d error\n%v/n", 2, []error{ce, pe})
t.Errorf(" Got: %d error\n%v\n", len(mes.Get()), mes.Get())
}
}
func TestKustomizationErrors_BatchAppend(t *testing.T) {
ce := ConfigmapError{Path: "kustomization/filepath", ErrorMsg: "can't find configmap name"}
pe := PatchError{KustomizationPath: "kustomization/filepath", PatchFilepath: "patch/path", ErrorMsg: "can't find patch file"}
mes := KustomizationErrors{kErrors: []error{ce}}
me := KustomizationErrors{kErrors: []error{pe}}
mes.BatchAppend(me)
if len(mes.Get()) != 2 {
t.Errorf("Incorrect KustomizationErrors.Append()\n")
t.Errorf(" Expected: %d error\n%v/n", 2, []error{ce, pe})
t.Errorf(" Got: %d error\n%v\n", len(mes.Get()), mes.Get())
}
}

View File

@@ -1,92 +0,0 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package error
import (
"fmt"
"strings"
"testing"
)
func TestManifestError_Error(t *testing.T) {
filepath := "/path/to/kustomize.yaml"
errorMsg := "Manifest not found"
me := ManifestError{ManifestFilepath: filepath, ErrorMsg: errorMsg}
if !strings.Contains(me.Error(), filepath) {
t.Errorf("Incorrect ManifestError.Error() message \n")
t.Errorf("Expected filepath %s, but unfound\n", filepath)
}
if !strings.Contains(me.Error(), errorMsg) {
t.Errorf("Incorrect ManifestError.Error() message \n")
t.Errorf("Expected errorMsg %s, but unfound\n", errorMsg)
}
}
func TestManifestErrors_Error(t *testing.T) {
filepath := "/path/to/kustomize"
me := ManifestError{ManifestFilepath: filepath, ErrorMsg: "Manifest not found"}
ce := ConfigmapError{ManifestFilepath: filepath, ErrorMsg: "can't find configmap name"}
pe := PatchError{ManifestFilepath: filepath, PatchFilepath: filepath, ErrorMsg: "can't find patch file"}
re := ResourceError{ManifestFilepath: filepath, ResourceFilepath: filepath, ErrorMsg: "can't find resource file"}
se := SecretError{ManifestFilepath: filepath, ErrorMsg: "can't find secret name"}
mes := ManifestErrors{merrors: []error{me, ce, pe, re, se}}
expectedErrorMsg := fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n", me.Error(), ce.Error(), pe.Error(), re.Error(), se.Error())
if mes.Error() != expectedErrorMsg {
t.Errorf("Incorrect ManifestErrors.Error() message\n")
t.Errorf(" Expected: %s\n", expectedErrorMsg)
t.Errorf(" Got: %s\n", mes.Error())
}
}
func TestManifestErrors_Get(t *testing.T) {
ce := ConfigmapError{ManifestFilepath: "manifest/filepath", ErrorMsg: "can't find configmap name"}
mes := ManifestErrors{merrors: []error{ce}}
if len(mes.Get()) != 1 {
t.Errorf("Incorrect ManifestErrors.Get()\n")
t.Errorf(" Expected: %v\n", []error{ce})
t.Errorf(" Got: %s\n", mes.Get())
}
}
func TestManifestErrors_Append(t *testing.T) {
ce := ConfigmapError{ManifestFilepath: "manifest/filepath", ErrorMsg: "can't find configmap name"}
pe := PatchError{ManifestFilepath: "manifest/filepath", PatchFilepath: "patch/path", ErrorMsg: "can't find patch file"}
mes := ManifestErrors{merrors: []error{ce}}
mes.Append(pe)
if len(mes.Get()) != 2 {
t.Errorf("Incorrect ManifestErrors.Append()\n")
t.Errorf(" Expected: %d error\n%v/n", 2, []error{ce, pe})
t.Errorf(" Got: %d error\n%v\n", len(mes.Get()), mes.Get())
}
}
func TestManifestErrors_BatchAppend(t *testing.T) {
ce := ConfigmapError{ManifestFilepath: "manifest/filepath", ErrorMsg: "can't find configmap name"}
pe := PatchError{ManifestFilepath: "manifest/filepath", PatchFilepath: "patch/path", ErrorMsg: "can't find patch file"}
mes := ManifestErrors{merrors: []error{ce}}
me := ManifestErrors{merrors: []error{pe}}
mes.BatchAppend(me)
if len(mes.Get()) != 2 {
t.Errorf("Incorrect ManifestErrors.Append()\n")
t.Errorf(" Expected: %d error\n%v/n", 2, []error{ce, pe})
t.Errorf(" Got: %d error\n%v\n", len(mes.Get()), mes.Get())
}
}

View File

@@ -21,11 +21,11 @@ import (
)
type PatchError struct {
ManifestFilepath string
PatchFilepath string
ErrorMsg string
KustomizationPath string
PatchFilepath string
ErrorMsg string
}
func (e PatchError) Error() string {
return fmt.Sprintf("Manifest file [%s] encounters a patch error for [%s]: %s\n", e.ManifestFilepath, e.PatchFilepath, e.ErrorMsg)
return fmt.Sprintf("Kustomization file [%s] encounters a patch error for [%s]: %s\n", e.KustomizationPath, e.PatchFilepath, e.ErrorMsg)
}

View File

@@ -25,7 +25,7 @@ func TestPatchError_Error(t *testing.T) {
filepath := "/path/to/kustomize.yaml"
patchfilepath := "/path/to/patch/patch.yaml"
errorMsg := "file not found"
me := PatchError{ManifestFilepath: filepath, PatchFilepath: patchfilepath, ErrorMsg: errorMsg}
me := PatchError{KustomizationPath: filepath, PatchFilepath: patchfilepath, ErrorMsg: errorMsg}
if !strings.Contains(me.Error(), filepath) {
t.Errorf("Incorrect PatchError.Error() message \n")
t.Errorf("Expected filepath %s, but unfound\n", filepath)

View File

@@ -20,11 +20,11 @@ import "fmt"
// First pass to encapsulate fields for more informative error messages.
type ResourceError struct {
ManifestFilepath string
ResourceFilepath string
ErrorMsg string
KustomizationPath string
ResourceFilepath string
ErrorMsg string
}
func (e ResourceError) Error() string {
return fmt.Sprintf("Manifest file [%s] encounters a resource error for [%s]: %s\n", e.ManifestFilepath, e.ResourceFilepath, e.ErrorMsg)
return fmt.Sprintf("Kustomization file [%s] encounters a resource error for [%s]: %s\n", e.KustomizationPath, e.ResourceFilepath, e.ErrorMsg)
}

View File

@@ -25,7 +25,7 @@ func TestResourceError_Error(t *testing.T) {
filepath := "/path/to/kustomize.yaml"
resourcefilepath := "/path/to/resource/deployment.yaml"
errorMsg := "file not found"
me := ResourceError{ManifestFilepath: filepath, ResourceFilepath: resourcefilepath, ErrorMsg: errorMsg}
me := ResourceError{KustomizationPath: filepath, ResourceFilepath: resourcefilepath, ErrorMsg: errorMsg}
if !strings.Contains(me.Error(), filepath) {
t.Errorf("Incorrect ResourceError.Error() message \n")
t.Errorf("Expected filepath %s, but unfound\n", filepath)

View File

@@ -19,10 +19,10 @@ package error
import "fmt"
type SecretError struct {
ManifestFilepath string
ErrorMsg string
KustomizationPath string
ErrorMsg string
}
func (e SecretError) Error() string {
return fmt.Sprintf("Manifest file [%s] encounters a secret error: %s\n", e.ManifestFilepath, e.ErrorMsg)
return fmt.Sprintf("Kustomization file [%s] encounters a secret error: %s\n", e.KustomizationPath, e.ErrorMsg)
}

View File

@@ -24,7 +24,7 @@ import (
func TestSecretError_Error(t *testing.T) {
filepath := "/path/to/secret.yaml"
errorMsg := "missing a command"
me := SecretError{ManifestFilepath: filepath, ErrorMsg: errorMsg}
me := SecretError{KustomizationPath: filepath, ErrorMsg: errorMsg}
if !strings.Contains(me.Error(), filepath) {
t.Errorf("Incorrect SecretError.Error() message \n")
t.Errorf("Expected filepath %s, but unfound\n", filepath)