Skip to content

Commit 97d83f8

Browse files
turan18sparr
authored andcommitted
Ensure version/revision are set during testing
Add link flags to our test target to ensure that the version and revision are set during unit tests. Signed-off-by: Yasin Turan <turyasin@amazon.com>
1 parent fd0003a commit 97d83f8

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ vendor:
8585

8686
test:
8787
@echo "$@"
88-
@GO111MODULE=$(GO111MODULE_VALUE) go test $(GO_TEST_FLAGS) -race ./...
88+
@GO111MODULE=$(GO111MODULE_VALUE) go test $(GO_TEST_FLAGS) $(GO_LD_FLAGS) -race ./...
8989

9090
integration: build
9191
@echo "$@"

version/version.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232

3333
package version
3434

35+
const Unset = "<unknown>"
36+
3537
var (
3638
// Version is the version number. Filled in at linking time (via Makefile).
37-
Version = "<unknown>"
39+
Version = Unset
3840

3941
// Revision is the VCS (e.g. git) revision. Filled in at linking time (via Makefile).
40-
Revision = "<unknown>"
42+
Revision = Unset
4143
)

version/version_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright The Soci Snapshotter Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
Copyright The containerd Authors.
19+
20+
Licensed under the Apache License, Version 2.0 (the "License");
21+
you may not use this file except in compliance with the License.
22+
You may obtain a copy of the License at
23+
24+
http://www.apache.org/licenses/LICENSE-2.0
25+
26+
Unless required by applicable law or agreed to in writing, software
27+
distributed under the License is distributed on an "AS IS" BASIS,
28+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+
See the License for the specific language governing permissions and
30+
limitations under the License.
31+
*/
32+
33+
package version
34+
35+
import "testing"
36+
37+
func TestVersion(t *testing.T) {
38+
if Version == Unset {
39+
t.Fatalf("version is unset")
40+
}
41+
}

0 commit comments

Comments
 (0)