-
Notifications
You must be signed in to change notification settings - Fork 465
/
version_daemon_test.go
71 lines (54 loc) · 1.72 KB
/
version_daemon_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cmd_test
import (
"fmt"
"io"
"net/http"
"os/exec"
"strings"
"testing"
"github.com/filecoin-project/venus/pkg/constants"
th "github.com/filecoin-project/venus/pkg/testhelpers"
tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags"
manet "github.com/multiformats/go-multiaddr/net"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestVersion(t *testing.T) {
tf.IntegrationTest(t)
commit := getCodeCommit(t)
verOut, err := exec.Command(th.MustGetFilecoinBinary(), "version").Output()
require.NoError(t, err)
version := string(verOut)
assert.Contains(t, version, fmt.Sprintf("%s+git.%s", constants.BuildVersion, commit[0:7]))
}
func TestVersionOverHttp(t *testing.T) {
tf.IntegrationTest(t)
td := th.NewDaemon(t).Start()
defer td.ShutdownSuccess()
maddr, err := td.CmdAddr()
require.NoError(t, err)
_, host, err := manet.DialArgs(maddr) // nolint
require.NoError(t, err)
url := fmt.Sprintf("http://%s/api/version", host)
req, err := http.NewRequest("POST", url, nil)
require.NoError(t, err)
token, _ := td.CmdToken()
req.Header.Add("Authorization", "Bearer "+token)
res, err := http.DefaultClient.Do(req)
require.NoError(t, err)
require.Equal(t, http.StatusOK, res.StatusCode)
commit := getCodeCommit(t)[0:7]
defer res.Body.Close() // nolint: errcheck
body, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.Contains(t, string(body), constants.BuildVersion+"+git."+commit)
}
func getCodeCommit(t *testing.T) string {
var gitOut []byte
var err error
gitArgs := []string{"rev-parse", "--verify", "HEAD"}
if gitOut, err = exec.Command("git", gitArgs...).Output(); err != nil {
assert.NoError(t, err)
}
return strings.TrimSpace(string(gitOut))
}