From 1d34132b87d9e4f94783a38e708e04d3b752c23e Mon Sep 17 00:00:00 2001 From: Sirajudeen Date: Thu, 16 Jul 2020 15:17:21 -0500 Subject: [PATCH] Added unit test for missing document functions * Added more unit tests to increase test coverage Change-Id: I292ddcd1c98ae49b37032a7d6111e063be397de3 --- pkg/document/document_test.go | 57 +++++++++++++++++++ .../testdata/common/initially_ignored.yaml | 7 +++ 2 files changed, 64 insertions(+) diff --git a/pkg/document/document_test.go b/pkg/document/document_test.go index 848512c95..6b082cac4 100644 --- a/pkg/document/document_test.go +++ b/pkg/document/document_test.go @@ -187,6 +187,63 @@ func TestDocument(t *testing.T) { assert.Equal(labelList["test-label"], "test-label-value") } }) + + t.Run("GetGroup", func(t *testing.T) { + doc, err := bundle.GetByName("some-random-deployment-we-will-filter") + require.NoError(err, "Unexpected error trying to GetByName") + group := doc.GetGroup() + require.NotNil(group) + assert.Equal(group, "apps") + }) + + t.Run("GetVersion", func(t *testing.T) { + doc, err := bundle.GetByName("some-random-deployment-we-will-filter") + require.NoError(err, "Unexpected error trying to GetByName") + version := doc.GetVersion() + require.NotNil(version) + assert.Equal(version, "v1") + }) + + t.Run("GetBool", func(t *testing.T) { + doc, err := bundle.GetByName("some-random-deployment-we-will-filter") + require.NoError(err, "Unexpected error trying to GetByName") + boolValue, err := doc.GetBool("spec.template.spec.containers[0].env[0].value") + require.NoError(err, "Unexpected error trying to GetBool from document") + assert.Equal(boolValue, false) + }) + + t.Run("GetFloat64", func(t *testing.T) { + doc, err := bundle.GetByName("some-random-deployment-we-will-filter") + require.NoError(err, "Unexpected error trying to GetByName") + floatValue, err := doc.GetFloat64("spec.template.spec.containers[0].env[1].value") + require.NoError(err, "Unexpected error trying to GetFloat from document") + assert.Equal(floatValue, float64(1.012)) + }) + + t.Run("GetInt64", func(t *testing.T) { + doc, err := bundle.GetByName("some-random-deployment-we-will-filter") + require.NoError(err, "Unexpected error trying to GetByName") + intValue, err := doc.GetInt64("spec.template.spec.containers[0].env[2].value") + require.NoError(err, "Unexpected error trying to GetInt from document") + assert.Equal(intValue, int64(1000)) + }) + + t.Run("GetSlice", func(t *testing.T) { + doc, err := bundle.GetByName("some-random-deployment-we-will-filter") + require.NoError(err, "Unexpected error trying to GetByName") + s := []interface{}{"foobar"} + gotSlice, err := doc.GetSlice("spec.template.spec.containers[0].args") + require.NoError(err, "Unexpected error trying to GetSlice") + assert.Equal(s, gotSlice) + }) + + t.Run("GetMap", func(t *testing.T) { + doc, err := bundle.GetByName("some-random-deployment-we-will-filter") + require.NoError(err, "Unexpected error trying to GetByName") + gotMap, err := doc.GetMap("spec.template.spec.containers[0].env[0]") + require.NoError(err, "Unexpected error trying to GetMap") + assert.NotNil(gotMap) + }) } func TestNewDocumentFromBytes(t *testing.T) { diff --git a/pkg/document/testdata/common/initially_ignored.yaml b/pkg/document/testdata/common/initially_ignored.yaml index 05c2c142f..91b77f925 100644 --- a/pkg/document/testdata/common/initially_ignored.yaml +++ b/pkg/document/testdata/common/initially_ignored.yaml @@ -20,5 +20,12 @@ spec: - foobar command: - somecommand + env: + - name: BOOL_FLAG + value: false + - name: FLOAT64_FLAG + value: 1.012 + - name: INT64_FLAG + value: 1000 image: someimage name: some-random-deployment-we-will-filter