mirror of
https://github.com/project-zot/zot.git
synced 2026-06-19 14:08:01 +08:00
2402296e9a
* fix: migrate to Go module v2 for proper semantic versioning This change updates the module path from 'zotregistry.dev/zot' to 'zotregistry.dev/zot/v2' to comply with Go's semantic versioning rules. According to Go's module versioning requirements, major version v2+ must include the major version in the module path. The current module path 'zotregistry.dev/zot' only supports v0.x.x and v1.x.x versions, making existing v2.x.x tags (like v2.1.8) unusable. Changes: - Updated go.mod module path to zotregistry.dev/zot/v2 - Updated all internal import paths across 280+ Go source files - Updated configuration files (golangcilint.yaml, gqlgen.yml) - Updated README.md Go reference badge This fix enables proper use of existing v2.x.x Git tags and allows external packages to import zot v2+ versions without compatibility errors. Resolves: Go module import compatibility for v2+ versions Fixes: #3071 Signed-off-by: Luca Muscariello <muscariello@ieee.org> * fix: regenerate GraphQL files with updated v2 import paths The gqlgen tool needs to regenerate the GraphQL schema files after the module path change to use the new v2 imports. Signed-off-by: Luca Muscariello <muscariello@ieee.org> --------- Signed-off-by: Luca Muscariello <muscariello@ieee.org>
169 lines
3.9 KiB
Go
169 lines
3.9 KiB
Go
//go:build events
|
|
// +build events
|
|
|
|
package events_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
cloudevents "github.com/cloudevents/sdk-go/v2"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
zerr "zotregistry.dev/zot/v2/errors"
|
|
eventsconf "zotregistry.dev/zot/v2/pkg/extensions/config/events"
|
|
"zotregistry.dev/zot/v2/pkg/extensions/events"
|
|
)
|
|
|
|
func TestHTTPSink(t *testing.T) {
|
|
Convey("NewHTTPSink returns error for invalid type", t, func() {
|
|
cfg := eventsconf.SinkConfig{
|
|
Type: "invalid",
|
|
Address: "http://localhost",
|
|
}
|
|
|
|
sink, err := events.NewHTTPSink(cfg)
|
|
So(sink, ShouldBeNil)
|
|
So(err, ShouldEqual, zerr.ErrInvalidEventSinkType)
|
|
})
|
|
|
|
Convey("NewHTTPSink returns error for empty address", t, func() {
|
|
cfg := eventsconf.SinkConfig{
|
|
Type: eventsconf.HTTP,
|
|
}
|
|
|
|
sink, err := events.NewHTTPSink(cfg)
|
|
So(sink, ShouldBeNil)
|
|
So(err, ShouldEqual, zerr.ErrEventSinkAddressEmpty)
|
|
})
|
|
|
|
Convey("NewHTTPSink returns sink for valid config", t, func() {
|
|
cfg := eventsconf.SinkConfig{
|
|
Type: eventsconf.HTTP,
|
|
Address: "http://localhost",
|
|
}
|
|
|
|
sink, err := events.NewHTTPSink(cfg)
|
|
So(err, ShouldBeNil)
|
|
So(sink, ShouldNotBeNil)
|
|
})
|
|
|
|
Convey("NewHTTPSink handles basic auth config", t, func() {
|
|
cfg := eventsconf.SinkConfig{
|
|
Type: eventsconf.HTTP,
|
|
Address: "http://localhost",
|
|
Credentials: &eventsconf.Credentials{
|
|
Username: "user",
|
|
Password: "pass",
|
|
},
|
|
}
|
|
|
|
sink, err := events.NewHTTPSink(cfg)
|
|
So(err, ShouldBeNil)
|
|
So(sink, ShouldNotBeNil)
|
|
})
|
|
|
|
Convey("NewHTTPSink handles token auth config", t, func() {
|
|
cfg := eventsconf.SinkConfig{
|
|
Type: eventsconf.HTTP,
|
|
Address: "http://localhost",
|
|
Credentials: &eventsconf.Credentials{
|
|
Token: "thisisamocktoken",
|
|
},
|
|
}
|
|
|
|
sink, err := events.NewHTTPSink(cfg)
|
|
So(err, ShouldBeNil)
|
|
So(sink, ShouldNotBeNil)
|
|
})
|
|
|
|
Convey("NewHTTPSink handles custom headers config", t, func() {
|
|
cfg := eventsconf.SinkConfig{
|
|
Type: eventsconf.HTTP,
|
|
Address: "http://localhost",
|
|
Headers: map[string]string{
|
|
"X-Tenant-ID": "tenant-abc123",
|
|
},
|
|
}
|
|
|
|
sink, err := events.NewHTTPSink(cfg)
|
|
So(err, ShouldBeNil)
|
|
So(sink, ShouldNotBeNil)
|
|
})
|
|
|
|
Convey("GetHTTPClientForConfig returns error for invalid proxy", t, func() {
|
|
badProxy := "://bad-url"
|
|
cfg := eventsconf.SinkConfig{
|
|
Proxy: &badProxy,
|
|
}
|
|
|
|
client, err := events.GetHTTPClientForConfig(cfg)
|
|
So(client, ShouldBeNil)
|
|
So(err, ShouldNotBeNil)
|
|
})
|
|
|
|
Convey("GetHTTPClientForConfig returns client with default transport", t, func() {
|
|
cfg := eventsconf.SinkConfig{
|
|
Timeout: 2 * time.Second,
|
|
}
|
|
|
|
client, err := events.GetHTTPClientForConfig(cfg)
|
|
So(err, ShouldBeNil)
|
|
So(client, ShouldNotBeNil)
|
|
})
|
|
|
|
Convey("BasicAuth encodes credentials", t, func() {
|
|
auth := events.BasicAuth("foo", "bar")
|
|
So(auth, ShouldEqual, "Zm9vOmJhcg==")
|
|
})
|
|
|
|
Convey("HTTPSink emits event and sets channel extension", t, func() {
|
|
event := cloudevents.NewEvent()
|
|
event.SetID("1234")
|
|
event.SetType("test.event")
|
|
event.SetSource("unit.test")
|
|
|
|
cfg := eventsconf.SinkConfig{
|
|
Type: eventsconf.HTTP,
|
|
Address: "http://localhost",
|
|
Timeout: 1 * time.Second,
|
|
Channel: "test-channel",
|
|
}
|
|
|
|
sink, err := events.NewHTTPSink(cfg)
|
|
So(err, ShouldBeNil)
|
|
|
|
_ = sink.Emit(&event)
|
|
So(event.Extensions()["channel"], ShouldEqual, "test-channel")
|
|
})
|
|
|
|
Convey("HTTPSink.Emit returns error for invalid event", t, func() {
|
|
event := cloudevents.NewEvent() // invalid
|
|
|
|
cfg := eventsconf.SinkConfig{
|
|
Type: eventsconf.HTTP,
|
|
Address: "http://localhost",
|
|
Timeout: 1 * time.Second,
|
|
}
|
|
|
|
sink, err := events.NewHTTPSink(cfg)
|
|
So(err, ShouldBeNil)
|
|
|
|
err = sink.Emit(&event)
|
|
So(err, ShouldNotBeNil)
|
|
})
|
|
|
|
Convey("HTTPSink.Close completes successfully", t, func() {
|
|
cfg := eventsconf.SinkConfig{
|
|
Type: eventsconf.HTTP,
|
|
Address: "http://localhost",
|
|
}
|
|
|
|
sink, err := events.NewHTTPSink(cfg)
|
|
So(err, ShouldBeNil)
|
|
|
|
err = sink.Close()
|
|
So(err, ShouldBeNil)
|
|
})
|
|
}
|