Skip to content

Commit 80eda15

Browse files
author
Roberto Sora
committed
add integration test for version info injection via vars
1 parent 403f713 commit 80eda15

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

Taskfile.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
version: '2'
22

3+
vars:
4+
TEST_VERSIONSTRING: "0.0.0-test.preview"
5+
TEST_COMMIT: "deadbeef"
6+
TEST_LDFLAGS_VALUE: >
7+
'-X github.com/arduino/arduino-cli/version.versionString={{.TEST_VERSIONSTRING}}
8+
-X github.com/arduino/arduino-cli/version.commit={{.TEST_COMMIT}}'
9+
310
tasks:
411
build:
512
desc: Build the project
@@ -20,4 +27,4 @@ tasks:
2027
test-integration:
2128
desc: Run integration tests only
2229
cmds:
23-
- go test -run Integration {{ default "-v" .GOFLAGS }} {{ default "./..." .TARGETS }}
30+
- go test -run Integration {{ default "-v" .GOFLAGS }} {{ default "./..." .TARGETS }} -ldflags {{.TEST_LDFLAGS_VALUE}}

version/version_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
5+
*
6+
* This software is released under the GNU General Public License defaultVersionString 3,
7+
* which covers the main part of arduino-cli.
8+
* The terms of this license can be found at:
9+
* https://www.gnu.org/licenses/gpl-3.0.en.html
10+
*
11+
* You can be released from the requirements of the above licenses by purchasing
12+
* a commercial license. Buying such a license is mandatory if you want to modify or
13+
* otherwise use the software for commercial activities involving the Arduino
14+
* software without disclosing the source code of your own applications. To purchase
15+
* a commercial license, send an email to license@arduino.cc.
16+
*/
17+
18+
package version
19+
20+
import (
21+
"testing"
22+
"time"
23+
24+
"github.com/stretchr/testify/require"
25+
)
26+
27+
// TestIntegrationBuildInjectedInfo is an integration test that aims to test the Info strings passed to the binary at build time
28+
// in order to have this test green launch your testing using the provided task (see /Taskfile.yml) or use:
29+
// go test -run Integration -v ./... -ldflags '-X github.com/arduino/arduino-cli/version.versionString=0.0.0-test.preview -X github.com/arduino/arduino-cli/version.commit=deadbeef'
30+
func TestIntegrationBuildInjectedInfo(t *testing.T) {
31+
if testing.Short() {
32+
t.Skip("skip integration test")
33+
}
34+
goldenAppName := "arduino-cli"
35+
goldenInfo := Info{
36+
Application: goldenAppName,
37+
VersionString: "0.0.0-test.preview",
38+
Commit: "deadbeef",
39+
BuildDate: time.Time{},
40+
}
41+
info := NewInfo(goldenAppName)
42+
require.Equal(t, goldenInfo.Application, info.Application)
43+
require.Equal(t, goldenInfo.VersionString, info.VersionString)
44+
require.Equal(t, goldenInfo.Commit, info.Commit)
45+
require.IsType(t, time.Time{}, info.BuildDate)
46+
require.False(t, info.BuildDate.IsZero())
47+
}

0 commit comments

Comments
 (0)