2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
2022-06-21 09:12:27 -04:00
|
|
|
"runtime/debug"
|
2022-03-22 11:03:15 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-03-09 09:23:42 -05:00
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
2022-03-22 11:03:15 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVersionCmd(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2022-06-08 02:14:28 -04:00
|
|
|
cmd := NewVersionCmd()
|
2022-04-13 07:01:38 -04:00
|
|
|
b := &bytes.Buffer{}
|
2022-03-22 11:03:15 -04:00
|
|
|
cmd.SetOut(b)
|
2023-03-09 09:23:42 -05:00
|
|
|
cmd.SetArgs([]string{})
|
2022-03-22 11:03:15 -04:00
|
|
|
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.NoError(err)
|
|
|
|
|
|
|
|
s, err := io.ReadAll(b)
|
|
|
|
assert.NoError(err)
|
2023-07-25 08:20:25 -04:00
|
|
|
assert.Contains(string(s), constants.BinaryVersion().String())
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
2022-06-21 09:12:27 -04:00
|
|
|
|
|
|
|
func TestParseBuildInfo(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
info := debug.BuildInfo{
|
|
|
|
GoVersion: "go1.18.3",
|
|
|
|
Settings: []debug.BuildSetting{
|
|
|
|
{
|
|
|
|
Key: "-compiler",
|
|
|
|
Value: "gc",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "GOARCH",
|
|
|
|
Value: "amd64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "GOOS",
|
|
|
|
Value: "linux",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "vcs.time",
|
|
|
|
Value: "2022-06-20T11:57:25Z",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "vcs.modified",
|
|
|
|
Value: "true",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "vcs.revision",
|
|
|
|
Value: "abcdef",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
commit, state, date, goVersion, compiler, platform := parseBuildInfo(&info)
|
|
|
|
|
|
|
|
assert.Equal("abcdef", commit)
|
|
|
|
assert.Equal("dirty", state)
|
|
|
|
assert.Equal("2022-06-20T11:57:25Z", date)
|
|
|
|
assert.Equal("go1.18.3", goVersion)
|
|
|
|
assert.Equal("gc", compiler)
|
|
|
|
assert.Equal("linux/amd64", platform)
|
|
|
|
}
|