|
| 1 | +package manifest_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "io/ioutil" |
| 5 | + "sort" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + |
| 10 | + . "github.com/databus23/helm-diff/manifest" |
| 11 | +) |
| 12 | + |
| 13 | +func foundObjects(result map[string]*MappingResult) []string { |
| 14 | + objs := make([]string, 0, len(result)) |
| 15 | + for k, _ := range result { |
| 16 | + objs = append(objs, k) |
| 17 | + } |
| 18 | + sort.Strings(objs) |
| 19 | + return objs |
| 20 | +} |
| 21 | + |
| 22 | +func TestPod(t *testing.T) { |
| 23 | + spec, err := ioutil.ReadFile("testdata/pod.yaml") |
| 24 | + require.NoError(t, err) |
| 25 | + |
| 26 | + require.Equal(t, |
| 27 | + []string{"default, nginx, Pod (v1)"}, |
| 28 | + foundObjects(Parse(string(spec), "default")), |
| 29 | + ) |
| 30 | +} |
| 31 | + |
| 32 | +func TestPodNamespace(t *testing.T) { |
| 33 | + spec, err := ioutil.ReadFile("testdata/pod_namespace.yaml") |
| 34 | + require.NoError(t, err) |
| 35 | + |
| 36 | + require.Equal(t, |
| 37 | + []string{"batcave, nginx, Pod (v1)"}, |
| 38 | + foundObjects(Parse(string(spec), "default")), |
| 39 | + ) |
| 40 | +} |
| 41 | + |
| 42 | +func TestDeployV1(t *testing.T) { |
| 43 | + spec, err := ioutil.ReadFile("testdata/deploy_v1.yaml") |
| 44 | + require.NoError(t, err) |
| 45 | + |
| 46 | + require.Equal(t, |
| 47 | + []string{"default, nginx, Deployment (apps)"}, |
| 48 | + foundObjects(Parse(string(spec), "default")), |
| 49 | + ) |
| 50 | +} |
| 51 | + |
| 52 | +func TestDeployV1Beta1(t *testing.T) { |
| 53 | + spec, err := ioutil.ReadFile("testdata/deploy_v1beta1.yaml") |
| 54 | + require.NoError(t, err) |
| 55 | + |
| 56 | + require.Equal(t, |
| 57 | + []string{"default, nginx, Deployment (apps)"}, |
| 58 | + foundObjects(Parse(string(spec), "default")), |
| 59 | + ) |
| 60 | +} |
0 commit comments