Skip to content

Commit

Permalink
Cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Oct 31, 2023
1 parent 4659e0b commit 821520f
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions internal/factsengine/gatherers/products_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gatherers_test

import (
"path"
"testing"

"github.com/spf13/afero"
Expand All @@ -9,33 +10,16 @@ import (
"github.com/trento-project/agent/pkg/factsengine/entities"
)

const testProductsPath string = "/etc/products.d/"

type ProductsGathererSuite struct {
suite.Suite
//fs afero.Fs
productsPath string
}

func TestProductsGathererSuite(t *testing.T) {
suite.Run(t, new(ProductsGathererSuite))
}

func (s *ProductsGathererSuite) SetupTest() {
// fs := afero.NewMemMapFs()
// err := fs.MkdirAll("/etc/products.d/", 0644)
// s.NoError(err)

// err = afero.WriteFile(fs, "/etc/products.d/baseproduct", []byte(`
// #!/bin/sh
// limit.descriptors=1048576
// systemctl --no-ask-password start SAPS41_40
// systemctl --no-ask-password start SADS41_41
// `), 0777)
// s.NoError(err)

// s.fs = fs
s.productsPath = "/etc/products.d/"
}

func (s *ProductsGathererSuite) TestProductsGathererFolderMissingError() {
fs := afero.NewMemMapFs()

Expand All @@ -47,7 +31,7 @@ func (s *ProductsGathererSuite) TestProductsGathererFolderMissingError() {
},
}

gatherer := gatherers.NewProductsGatherer(fs, s.productsPath)
gatherer := gatherers.NewProductsGatherer(fs, testProductsPath)

results, err := gatherer.Gather(fr)
s.Nil(results)
Expand All @@ -58,7 +42,7 @@ func (s *ProductsGathererSuite) TestProductsGathererFolderMissingError() {
func (s *ProductsGathererSuite) TestProductsGathererReadingError() {
fs := afero.NewMemMapFs()

err := afero.WriteFile(fs, "/etc/products.d/baseproduct", []byte(`
err := afero.WriteFile(fs, path.Join(testProductsPath, "baseproduct"), []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<product schemeversion="0">
<vendor>openSUSE</vendor>
Expand All @@ -77,7 +61,7 @@ func (s *ProductsGathererSuite) TestProductsGathererReadingError() {
},
}

gatherer := gatherers.NewProductsGatherer(fs, s.productsPath)
gatherer := gatherers.NewProductsGatherer(fs, testProductsPath)

results, err := gatherer.Gather(fr)
s.Nil(results)
Expand All @@ -89,7 +73,7 @@ func (s *ProductsGathererSuite) TestProductsGathererReadingError() {
func (s *ProductsGathererSuite) TestProductsGathererSuccess() {
fs := afero.NewMemMapFs()

err := afero.WriteFile(fs, "/etc/products.d/baseproduct", []byte(`
err := afero.WriteFile(fs, path.Join(testProductsPath, "baseproduct"), []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<product schemeversion="0">
<vendor>openSUSE</vendor>
Expand All @@ -101,8 +85,9 @@ func (s *ProductsGathererSuite) TestProductsGathererSuccess() {
</urls>
</product>
`), 0777)
s.NoError(err)

err = afero.WriteFile(fs, "/etc/products.d/otherproduct", []byte(`
err = afero.WriteFile(fs, path.Join(testProductsPath, "otherproduct"), []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<product schemeversion="0">
<vendor>openSUSE</vendor>
Expand All @@ -111,7 +96,6 @@ func (s *ProductsGathererSuite) TestProductsGathererSuccess() {
<release>1</release>
</product>
`), 0777)

s.NoError(err)

fr := []entities.FactRequest{
Expand All @@ -122,7 +106,7 @@ func (s *ProductsGathererSuite) TestProductsGathererSuccess() {
},
}

gatherer := gatherers.NewProductsGatherer(fs, s.productsPath)
gatherer := gatherers.NewProductsGatherer(fs, testProductsPath)

expectedFacts := []entities.Fact{
{
Expand Down

0 comments on commit 821520f

Please sign in to comment.