-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Introduce basic testing for the version
module
#1111
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package version | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewDefraVersion(t *testing.T) { | ||
dv, err := NewDefraVersion() | ||
assert.NoError(t, err) | ||
|
||
assert.NotEmpty(t, dv.VersionHTTPAPI) | ||
assert.NotEmpty(t, dv.NetProtocol) | ||
assert.NotEmpty(t, dv.DocKeyVersions) | ||
|
||
// because these are set by the build system, we expect them to be empty in this unit test... | ||
assert.Empty(t, dv.GoInfo) | ||
assert.Empty(t, dv.Release) | ||
assert.Empty(t, dv.Commit) | ||
assert.Empty(t, dv.CommitDate) | ||
} | ||
|
||
func TestDefraVersionString(t *testing.T) { | ||
dv := defraVersion{ | ||
Release: "test-release", | ||
Commit: "abc123def456", | ||
CommitDate: "2022-01-01T12:00:00Z", | ||
GoInfo: "1.17.5", | ||
} | ||
assert.Equal(t, dv.String(), "defradb test-release (abc123de 2022-01-01T12:00:00Z) built with Go 1.17.5") | ||
} | ||
|
||
func TestDefraVersionStringFull(t *testing.T) { | ||
dv := defraVersion{ | ||
Release: "test-release", | ||
Commit: "abc123def456", | ||
CommitDate: "2022-01-01T12:00:00Z", | ||
GoInfo: "1.17.5", | ||
VersionHTTPAPI: "v0", | ||
DocKeyVersions: "1", | ||
NetProtocol: "/defra/0.0.1", | ||
} | ||
|
||
expected := `defradb test-release (abc123de 2022-01-01T12:00:00Z) | ||
* HTTP API: v0 | ||
* P2P multicodec: /defra/0.0.1 | ||
* DocKey versions: 1 | ||
* Go: 1.17.5` | ||
|
||
assert.Equal(t, expected, dv.StringFull()) | ||
} | ||
|
||
func TestDefraVersion_JSON(t *testing.T) { | ||
dv1 := defraVersion{ | ||
Release: "test-release", | ||
Commit: "abc123def456", | ||
CommitDate: "2022-01-01T12:00:00Z", | ||
GoInfo: "go1.17.5", | ||
VersionHTTPAPI: "1.2.3", | ||
DocKeyVersions: "0123456789abcdef", | ||
NetProtocol: "test-protocol", | ||
} | ||
|
||
_, err := json.Marshal(dv1) | ||
assert.NoError(t, err) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Will this test not be run on release once these variables have been set? And will this not cause the build/tests to fail for anyone running them on a release branch/tag/whatever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variables are set in the
Makefile
viaBUILD_FLAGS
and they are only passed for building defradb and not testing defradb.For now, this allows to run the tests outside of using make.
I suggest (to myself) adding a comment indicating that assumption.
We might want to run these tests at some point in the future using BUILD_FLAGS, I'm unsure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it - thanks Orpheus :) New comment looks good too