0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-23 22:27:35 -05:00
zot/pkg/compliance/v1_0_0/check_test.go

64 lines
1.1 KiB
Go
Raw Normal View History

2019-10-09 13:50:10 -05:00
package v1_0_0_test
import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
"github.com/anuvu/zot/pkg/api"
"github.com/anuvu/zot/pkg/compliance"
"github.com/anuvu/zot/pkg/compliance/v1_0_0"
"gopkg.in/resty.v1"
)
const (
Address = "127.0.0.1"
Port = "8080"
)
func TestWorkflows(t *testing.T) {
v1_0_0.CheckWorkflows(t, &compliance.Config{Address: Address, Port: Port})
}
func TestMain(m *testing.M) {
config := api.NewConfig()
config.HTTP.Address = Address
config.HTTP.Port = Port
c := api.NewController(config)
dir, err := ioutil.TempDir("", "oci-repo-test")
2019-10-09 13:50:10 -05:00
if err != nil {
panic(err)
}
//defer os.RemoveAll(dir)
c.Config.Storage.RootDirectory = dir
2019-10-09 13:50:10 -05:00
go func() {
// this blocks
if err := c.Run(); err != nil {
return
}
}()
BaseURL := fmt.Sprintf("http://%s:%s", Address, Port)
2019-10-09 13:50:10 -05:00
for {
// poll until ready
resp, _ := resty.R().Get(BaseURL)
if resp.StatusCode() == 404 {
break
}
2019-10-09 13:50:10 -05:00
time.Sleep(100 * time.Millisecond)
}
2019-10-09 13:50:10 -05:00
status := m.Run()
ctx := context.Background()
_ = c.Server.Shutdown(ctx)
2019-10-09 13:50:10 -05:00
os.Exit(status)
}