Tinkerbell.Sandbox/cmd/bump-version/image/image_test.go
Gianluca Arbezzano d6a057c89d New tool to bump current_versions.sh automatically
This commit contains a new utility that helps to automate a version bump
for sandbox.

You can run this command to get the vibe of what it does.

```
$ go run cmd/bump-version/main.go -help
```

In order to try it out you can run this command form sandbox root. By
default it won't overwrite anything. It will print to stdout a new
version of the current_versions.sh file where all the images are
calculate cloning the various repositories

```
$ go run cmd/bump-version/main.go
```

If you want to overwrite the current_versions file you can use the flag
`-overwrite`.

More will come but for now, that's the PoC. Ideally this can be hooked
to CI/CD and run periodically, opening a PR that can be evaluated and
merged.

Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
2021-02-12 14:47:46 +01:00

40 lines
664 B
Go

package image_test
import (
"errors"
"fmt"
"testing"
"github.com/tinkerbell/sandbox/cmd/bump-version/image"
)
func TestTagFromSha(t *testing.T) {
s := []struct {
Err error
Commit string
Tag string
}{
{
Commit: "a7e947efc194fb0375f88cccc67f2fde5e0c85c1",
Tag: "sha-a7e947ef",
},
{
Commit: "0",
Err: image.ErrCommitTooShort,
},
}
for _, v := range s {
t.Run(fmt.Sprintf("%s -> %s", v.Commit, v.Tag), func(t *testing.T) {
tag, err := image.TagFromSha(v.Commit)
errors.Is(err, v.Err)
if v.Err != err {
t.Error(err)
}
if tag != v.Tag {
t.Errorf("expected %s got %s", v.Tag, tag)
}
})
}
}