Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c916eb4

Browse files
committedNov 23, 2020
Add test for result.WriteReport()
1 parent accad46 commit c916eb4

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
 

‎result/result_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// This file is part of arduino-check.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-check.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package result
17+
18+
import (
19+
"io/ioutil"
20+
"os"
21+
"testing"
22+
23+
"github.com/arduino/arduino-check/configuration"
24+
"github.com/arduino/arduino-check/util/test"
25+
"github.com/arduino/go-paths-helper"
26+
"github.com/stretchr/testify/assert"
27+
"github.com/stretchr/testify/require"
28+
)
29+
30+
func TestWriteReport(t *testing.T) {
31+
flags := test.ConfigurationFlags()
32+
33+
projectPaths := []string{"/foo"}
34+
35+
reportFolderPathString, err := ioutil.TempDir("", "arduino-check-result-TestWriteReport")
36+
require.Nil(t, err)
37+
defer os.RemoveAll(reportFolderPathString) // clean up
38+
reportFolderPath := paths.New(reportFolderPathString)
39+
40+
reportFilePath := reportFolderPath.Join("report-file.json")
41+
flags.Set("report-file", reportFilePath.String())
42+
assert.Nil(t, configuration.Initialize(flags, projectPaths))
43+
assert.NoError(t, Results.WriteReport())
44+
45+
reportFile, err := reportFilePath.Open()
46+
require.Nil(t, err)
47+
reportFileInfo, err := reportFile.Stat()
48+
require.Nil(t, err)
49+
reportFileBytes := make([]byte, reportFileInfo.Size())
50+
_, err = reportFile.Read(reportFileBytes)
51+
require.Nil(t, err)
52+
assert.True(t, assert.ObjectsAreEqualValues(reportFileBytes, Results.jsonReportRaw()), "Report file contents are correct")
53+
}

0 commit comments

Comments
 (0)
Please sign in to comment.