You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
69 lines
1.8 KiB
package coreutils |
|
|
|
import ( |
|
"bytes" |
|
"github.com/stretchr/testify/assert" |
|
"github.com/stretchr/testify/suite" |
|
"path" |
|
"strings" |
|
"testing" |
|
) |
|
|
|
type CheckLineTestSuite struct { |
|
suite.Suite |
|
} |
|
|
|
func (suite *CheckLineTestSuite) TestImproperlyFormattedLine() { |
|
t := suite.T() |
|
valid, err := checkLine("name chef", MD5Regex, MD5Sum) |
|
assert.Equal(t, false, valid) |
|
assert.Error(t, err) |
|
assert.Equal(t, ImproperlyFormattedErr, err) |
|
} |
|
|
|
func (suite *CheckLineTestSuite) TestMismatchedChecksum() { |
|
t := suite.T() |
|
line := "4a5fb9ebd6c8ea7efb53d071053ef778 " + path.Join("test_data", "some_file.txt") |
|
valid, err := checkLine(line, MD5Regex, MD5Sum) |
|
assert.Equal(t, false, valid) |
|
assert.NoError(t, err) |
|
} |
|
|
|
func (suite *CheckLineTestSuite) TestValid() { |
|
t := suite.T() |
|
line := "6a5fb9ebd6c8ea7efb53d071053ef778 " + path.Join("test_data", "some_file.txt") |
|
valid, err := checkLine(line, MD5Regex, MD5Sum) |
|
assert.Equal(t, true, valid) |
|
assert.NoError(t, err) |
|
} |
|
|
|
func TestCheckLineTestSuite(t *testing.T) { |
|
suite.Run(t, new(CheckLineTestSuite)) |
|
} |
|
|
|
type CheckSumsInReaderTestSuite struct { |
|
suite.Suite |
|
} |
|
|
|
func (suite *CheckSumsInReaderTestSuite) Test() { |
|
t := suite.T() |
|
buf := bytes.NewBufferString(strings.Join( |
|
[]string{ |
|
"name chef", |
|
"4a5fb9ebd6c8ea7efb53d071053ef778 " + path.Join("test_data", "some_file.txt"), |
|
"6a5fb9ebd6c8ea7efb53d071053ef778 " + path.Join("test_data", "some_file.txt"), |
|
"4a5fb9ebd6c8ea7efb53d071053ef778 nonexistant_file", |
|
}, |
|
"\n", |
|
)) |
|
results, err := CheckSumsInReader(buf, MD5Regex, MD5Sum) |
|
assert.NotNil(t, results) |
|
assert.Equal(t, uint(1), results.ImproperlyFormattedCount) |
|
assert.Equal(t, uint(1), results.FilesNotRead) |
|
assert.Equal(t, uint(1), results.InvalidChecksumCount) |
|
assert.NoError(t, err) |
|
} |
|
|
|
func TestCheckSumsInReaderTestSuite(t *testing.T) { |
|
suite.Run(t, new(CheckSumsInReaderTestSuite)) |
|
}
|
|
|