From e35664d4ddc530448abdfbbb8c563cf814916a7a Mon Sep 17 00:00:00 2001 From: Marina Moore Date: Fri, 18 Feb 2022 11:21:47 -0500 Subject: [PATCH] Add tests for tuf-repository Signed-off-by: Marina Moore --- tuf-repository_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tuf-repository_test.go diff --git a/tuf-repository_test.go b/tuf-repository_test.go new file mode 100644 index 0000000..91b317d --- /dev/null +++ b/tuf-repository_test.go @@ -0,0 +1,44 @@ +package tufnotary + +import ( + "io/ioutil" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +type TufTestSuite struct { + suite.Suite +} + +func (suite *TufTestSuite) SetupTest() { +} + +func (suite *TufTestSuite) TestInit() { + //TODO made then delete temp repo for testing + err := Init("test_repo") + assert.Nil(suite.T(), err) + + root, err := ioutil.ReadFile("test_repo/staged/root.json") + assert.Nil(suite.T(), err) + assert.True(suite.T(), strings.Contains(string(root), "\"_type\":\"root\"")) + assert.True(suite.T(), strings.Contains(string(root), "\"consistent_snapshot\":false")) + + targets, err := ioutil.ReadFile("test_repo/staged/targets.json") + assert.Nil(suite.T(), err) + assert.True(suite.T(), strings.Contains(string(targets), "\"_type\":\"targets\"")) + + timestamp, err := ioutil.ReadFile("test_repo/staged/timestamp.json") + assert.Nil(suite.T(), err) + assert.True(suite.T(), strings.Contains(string(timestamp), "\"_type\":\"timestamp\"")) + + snapshot, err := ioutil.ReadFile("test_repo/staged/snapshot.json") + assert.Nil(suite.T(), err) + assert.True(suite.T(), strings.Contains(string(snapshot), "\"_type\":\"snapshot\"")) +} + +func TestTufTestSuite(t *testing.T) { + suite.Run(t, new(TufTestSuite)) +}