+++ /dev/null
-# Copyright (c) 2019 AT&T Intellectual Property.
-# Copyright (c) 2019 Nokia.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-#------------------------------------------------------------------------------
-#
-#------------------------------------------------------------------------------
-ifndef ROOT_DIR
-$(error ROOT_DIR NOT DEFINED)
-endif
-ifndef CACHE_DIR
-$(error CACHE_DIR NOT DEFINED)
-endif
-
-#------------------------------------------------------------------------------
-#
-#------------------------------------------------------------------------------
-
-GO_CACHE_DIR?=$(abspath $(CACHE_DIR)/go)
-
-#------------------------------------------------------------------------------
-#
-#------------------------------------------------------------------------------
-ifndef MAKE_GO_TARGETS
-MAKE_GO_TARGETS:=1
-
-
-.PHONY: FORCE go-build go-test go-test-fmt go-fmt go-clean
-
-FORCE:
-
-
-GOOS=$(shell go env GOOS)
-GOCMD=go
-GOBUILD=$(GOCMD) build -a -installsuffix cgo
-GORUN=$(GOCMD) run -a -installsuffix cgo
-GOCLEAN=$(GOCMD) clean
-GOTEST=$(GOCMD) test -v
-GOGET=$(GOCMD) get
-
-GOFILES:=$(shell find $(ROOT_DIR) -name '*.go' -not -name '*_test.go')
-GOALLFILES:=$(shell find $(ROOT_DIR) -name '*.go')
-GOMODFILES:=go.mod go.sum
-
-
-.SECONDEXPANSION:
-$(GO_CACHE_DIR)/%: $(GOFILES) $(GOMODFILES) $$(BUILDDEPS)
- @echo "Building:\t$*"
- GO111MODULE=on GO_ENABLED=0 GOOS=linux $(GOBUILD) -o $@ cmd/appmgr.go
-
-
-.SECONDEXPANSION:
-$(GO_CACHE_DIR)/%_test: $(GOALLFILES) $(GOMODFILES) $$(BUILDDEPS) FORCE
- @echo "Testing:\t$*"
- GO111MODULE=on GO_ENABLED=0 GOOS=linux $(GOTEST) -coverprofile $(COVEROUT) ./pkg/resthooks/ ./pkg/helm/ ./pkg/cm/
- test -e $@ && (eval $(TESTENV) $@ -test.coverprofile $(COVEROUT) || false) || true
- test -e $@ && (go tool cover -html=$(COVEROUT) -o $(COVERHTML) || false) || true
-
-
-.SECONDEXPANSION:
-go-build: GO_TARGETS:=
-go-build: $$(GO_TARGETS)
-
-.SECONDEXPANSION:
-go-test: GO_TARGETS:=
-go-test: $$(GO_TARGETS)
-
-go-test-fmt: $(GOFILES)
- @(RESULT="$$(gofmt -l $^)"; test -z "$${RESULT}" || (echo -e "gofmt failed:\n$${RESULT}" && false) )
-
-go-fmt: $(GOFILES)
- gofmt -w -s $^
-
-go-mod-tidy: FORCE
- GO111MODULE=on go mod tidy
-
-go-mod-download: FORCE
- GO111MODULE=on go mod download
-
-go-clean: GO_TARGETS:=
-go-clean:
- @echo " > Cleaning build cache"
- @-rm -rf $(GO_TARGETS)* 2> /dev/null
- go clean 2> /dev/null
-
-
-endif
-
-#------------------------------------------------------------------------------
-#
-#-------------------------------------------------------------------- ----------
-
-$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME): BUILDDEPS:=$(XAPP_BUILDDEPS)
-
-
-$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: BUILDDEPS:=$(XAPP_BUILDDEPS)
-$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: COVEROUT:=$(abspath $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_cover.out)
-$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: COVERHTML:=$(abspath $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_cover.html)
-$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test: TESTENV:=$(XAPP_TESTENV)
-
-go-build: GO_TARGETS+=$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)
-go-test: GO_TARGETS+=$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test
-go-clean: GO_TARGETS+=$(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME) $(GO_CACHE_DIR)/$(XAPP_ROOT)/$(XAPP_NAME)_test
-
"gerrit.oran-osc.org/r/ric-plt/appmgr/pkg/models"
)
+var rh *Resthook
var resp models.SubscriptionResponse
// Test cases
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(""))
}
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 {