X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=pkg%2Fresthooks%2Fresthooks_test.go;h=d1ac790132607a7e07599d3bbad66fdb27e5a81c;hb=45ea51f2a77c4aa22546224b4ded0d3cb03425e6;hp=018dee8b10711c41e2a5eac39d1922fdd257f9d7;hpb=34e4383c438f87023bc411d9b0baa4a828a7e306;p=ric-plt%2Fappmgr.git diff --git a/pkg/resthooks/resthooks_test.go b/pkg/resthooks/resthooks_test.go index 018dee8..d1ac790 100755 --- a/pkg/resthooks/resthooks_test.go +++ b/pkg/resthooks/resthooks_test.go @@ -24,10 +24,11 @@ import ( "os" "testing" - "gerrit.oran-osc.org/r/ric-plt/appmgr/pkg/appmgr" - "gerrit.oran-osc.org/r/ric-plt/appmgr/pkg/models" + "gerrit.o-ran-sc.org/r/ric-plt/appmgr/pkg/appmgr" + "gerrit.o-ran-sc.org/r/ric-plt/appmgr/pkg/models" ) +var rh *Resthook var resp models.SubscriptionResponse // Test cases @@ -35,88 +36,89 @@ func TestMain(m *testing.M) { appmgr.Init() appmgr.Logger.SetLevel(0) + rh = NewResthook(false) code := m.Run() os.Exit(code) } func TestAddSubscriptionSuccess(t *testing.T) { - resp := NewResthook().AddSubscription(CreateSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")) + resp := rh.AddSubscription(CreateSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")) assert.Equal(t, resp.Version, int64(0)) assert.Equal(t, resp.EventType, models.EventTypeCreated) } func TestAddSubscriptionExists(t *testing.T) { - resp := NewResthook().AddSubscription(CreateSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")) + resp := rh.AddSubscription(CreateSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")) assert.Equal(t, resp.Version, int64(0)) - assert.Equal(t, resp.EventType, models.EventType("")) + assert.Equal(t, resp.EventType, models.EventTypeCreated) } func TestDeletesubscriptionSuccess(t *testing.T) { - resp := NewResthook().AddSubscription(CreateSubscription(models.EventTypeDeleted, int64(5), int64(10), "http://localhost:8087/xapps_hook2")) + resp := rh.AddSubscription(CreateSubscription(models.EventTypeDeleted, int64(5), int64(10), "http://localhost:8087/xapps_hook2")) assert.Equal(t, resp.Version, int64(0)) assert.Equal(t, resp.EventType, models.EventTypeDeleted) - resp, ok := NewResthook().DeleteSubscription(resp.ID) + resp, ok := rh.DeleteSubscription(resp.ID) assert.Equal(t, ok, true) assert.Equal(t, resp.Version, int64(0)) assert.Equal(t, resp.EventType, models.EventTypeDeleted) } func TestDeletesubscriptionInvalid(t *testing.T) { - resp, ok := NewResthook().DeleteSubscription("Non-existent-ID") + resp, ok := rh.DeleteSubscription("Non-existent-ID") assert.Equal(t, ok, false) assert.Equal(t, resp.Version, int64(0)) assert.Equal(t, resp.EventType, models.EventType("")) } func TestModifySubscriptionSuccess(t *testing.T) { - resp := NewResthook().AddSubscription(CreateSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook2")) + resp := rh.AddSubscription(CreateSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook2")) assert.Equal(t, resp.Version, int64(0)) assert.Equal(t, resp.EventType, models.EventTypeCreated) - resp, ok := NewResthook().ModifySubscription(resp.ID, CreateSubscription(models.EventTypeModified, int64(5), int64(10), "http://localhost:8087/xapps_hook2")) + resp, ok := rh.ModifySubscription(resp.ID, CreateSubscription(models.EventTypeModified, int64(5), int64(10), "http://localhost:8087/xapps_hook2")) assert.Equal(t, ok, true) assert.Equal(t, resp.Version, int64(0)) assert.Equal(t, resp.EventType, models.EventTypeModified) } func TestModifysubscriptionInvalid(t *testing.T) { - resp, ok := NewResthook().DeleteSubscription("Non-existent-ID") + resp, ok := rh.DeleteSubscription("Non-existent-ID") assert.Equal(t, ok, false) assert.Equal(t, resp.Version, int64(0)) assert.Equal(t, resp.EventType, models.EventType("")) } func TestGetAllSubscriptionSuccess(t *testing.T) { - NewResthook().FlushSubscriptions() - subscriptions := NewResthook().GetAllSubscriptions() + rh.FlushSubscriptions() + subscriptions := rh.GetAllSubscriptions() assert.Equal(t, len(subscriptions), 0) - NewResthook().AddSubscription(CreateSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")) - NewResthook().AddSubscription(CreateSubscription(models.EventTypeModified, int64(5), int64(10), "http://localhost:8087/xapps_hook2")) + rh.AddSubscription(CreateSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")) + rh.AddSubscription(CreateSubscription(models.EventTypeModified, int64(5), int64(10), "http://localhost:8087/xapps_hook2")) - subscriptions = NewResthook().GetAllSubscriptions() + subscriptions = rh.GetAllSubscriptions() assert.Equal(t, len(subscriptions), 2) } func TestGetSubscriptionByIdSuccess(t *testing.T) { - NewResthook().FlushSubscriptions() + rh.FlushSubscriptions() sub1 := CreateSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook") sub2 := CreateSubscription(models.EventTypeModified, int64(5), int64(10), "http://localhost:8087/xapps_hook2") - r1 := NewResthook().AddSubscription(sub1) - r2 := NewResthook().AddSubscription(sub2) + r1 := rh.AddSubscription(sub1) + r2 := rh.AddSubscription(sub2) - resp1, ok := NewResthook().GetSubscriptionById(r1.ID) + resp1, ok := rh.GetSubscriptionById(r1.ID) assert.Equal(t, ok, true) assert.Equal(t, resp1.Data, sub1.Data) - resp2, ok := NewResthook().GetSubscriptionById(r2.ID) + resp2, ok := rh.GetSubscriptionById(r2.ID) assert.Equal(t, ok, true) assert.Equal(t, resp2.Data, sub2.Data) } func TestTeardown(t *testing.T) { - NewResthook().FlushSubscriptions() + rh.FlushSubscriptions() } func CreateSubscription(et models.EventType, maxRetries, retryTimer int64, targetUrl string) models.SubscriptionRequest {