Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test coverage reporting for gitlab #140

Merged
merged 5 commits into from Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitlab-ci.jsonnet
Expand Up @@ -77,8 +77,8 @@ local jobs = {
},

'unit-tests': unittest_stage {
coverage: @"/^TOTAL.*\s+(\d+\%)\s*$/",
script: ["make vendor", "make test"],
coverage: @"/\d\d\.\d.$/",
script: ["make vendor", "make test", "make cover"],
},

// End2End tests
Expand Down
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Expand Up @@ -183,11 +183,12 @@ unit-tests:
- mkdir -p $GOPATH/src/github.com/coreos-inc/alm
- cp -a $CI_PROJECT_DIR/* $GOPATH/src/github.com/coreos-inc/alm
- cd $GOPATH/src/github.com/coreos-inc/alm
coverage: /^TOTAL.*\s+(\d+\%)\s*$/
coverage: /\d\d\.\d.$/
image: quay.io/coreos/alm-ci:${CI_COMMIT_REF_SLUG}
script:
- make vendor
- make test
- make cover
stage: tests
tags:
- kubernetes
Expand Down
2 changes: 1 addition & 1 deletion Documentation/design/resources/schema_test.go
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
)
Expand Down
29 changes: 15 additions & 14 deletions Makefile
Expand Up @@ -5,26 +5,27 @@ CATALOG_PKG := github.com/coreos-inc/alm/cmd/catalog
CATALOG_EXECUTABLE := ./bin/catalog
IMAGE_REPO := quay.io/coreos/alm
IMAGE_TAG ?= "dev"
TOP_LEVEL := $(dir $(shell glide novendor))
PACKAGES := $(shell find $(TOP_LEVEL) -type d -not -path '*/\.*')

.PHONY: test run clean vendor vendor-update coverage

all: test build

test:
go vet `glide novendor`
go test -v -race `glide novendor`
go vet ./pkg/...
go test -v -race ./pkg/...
go test -v ./Documentation/...

cover:
go test -cover -tags test `glide novendor`
COVERUTIL := $(GOPATH)/bin/gocoverutil

coverage-html:
echo "mode: count" > coverage-all.out
$(foreach pkg,$(PACKAGES),\
go test -coverprofile=coverage.out -covermode=count -tags test $(pkg);\
tail -n +2 coverage.out >> coverage-all.out;)
go tool cover -html=coverage-all.out
$(COVERUTIL):
go get -u github.com/AlekSi/gocoverutil

cover: $(COVERUTIL)
$(COVERUTIL) -coverprofile=cover.out test -covermode=count ./pkg/...
go tool cover -func=cover.out

coverage-html: cover
go tool cover -html=cover.out

build:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -i -o $(ALM_EXECUTABLE) $(ALM_PKG)
Expand Down Expand Up @@ -73,9 +74,9 @@ generate-mock-client: $(MOCKGEN)
mockgen -source=client/alphacatalogentry_client.go -package=catalog > catalog/zz_generated.mock_alphacatalogentry_client_test.go
mockgen -source=client/deployment_install_client.go -package=install > install/zz_generated.mock_deployment_install_client_test.go
# can't use "source" mockgen, see: https://github.com/golang/mock/issues/11#issuecomment-294380653
mockgen -package=alm -imports client=github.com/coreos-inc/alm/vendor/github.com/coreos-inc/operator-client/pkg/client,v1=github.com/coreos-inc/alm/vendor/k8s.io/apimachinery/pkg/apis/meta/v1 github.com/coreos-inc/alm/install StrategyResolverInterface > operators/alm/zz_generated.mock_resolver_test.go
mockgen -package=alm -imports client=github.com/coreos-inc/alm/pkg/vendor/github.com/coreos-inc/operator-client/pkg/client,v1=github.com/coreos-inc/alm/pkg/vendor/k8s.io/apimachinery/pkg/apis/meta/v1 github.com/coreos-inc/alm/pkg/install StrategyResolverInterface > operators/alm/zz_generated.mock_resolver_test.go
# mockgen doesn't handle vendored dependencies well: https://github.com/golang/mock/issues/30
sed -i '' s,github.com/coreos-inc/alm/vendor/,, operators/alm/zz_generated.mock_resolver_test.go
sed -i '' s,github.com/coreos-inc/alm/pkg/vendor/,, operators/alm/zz_generated.mock_resolver_test.go
goimports -w operators/alm/zz_generated.mock_resolver_test.go

make gen-all: gen-ci codegen generate-mock-client
4 changes: 2 additions & 2 deletions cmd/alm/main.go
Expand Up @@ -13,8 +13,8 @@ import (

"fmt"

"github.com/coreos-inc/alm/annotater"
"github.com/coreos-inc/alm/operators/alm"
"github.com/coreos-inc/alm/pkg/annotater"
"github.com/coreos-inc/alm/pkg/operators/alm"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions cmd/catalog/main.go
Expand Up @@ -11,9 +11,9 @@ import (

log "github.com/sirupsen/logrus"

source "github.com/coreos-inc/alm/catalog"
"github.com/coreos-inc/alm/client"
"github.com/coreos-inc/alm/operators/catalog"
source "github.com/coreos-inc/alm/pkg/catalog"
"github.com/coreos-inc/alm/pkg/client"
"github.com/coreos-inc/alm/pkg/operators/catalog"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions hack/k8s/codegen/run_in_docker.sh
Expand Up @@ -14,8 +14,8 @@ api_groups=("clusterserviceversion:v1alpha1" "installplan:v1alpha1"
for group in ${api_groups[@]}; do
echo -n "[$group] "
codegen::generate-groups deepcopy \
github.com/coreos-inc/alm/generated \
github.com/coreos-inc/alm/apis \
github.com/coreos-inc/alm/pkg/generated \
github.com/coreos-inc/alm/pkg/apis \
$group \
--go-header-file "./hack/k8s/codegen/boilerplate.go.txt"
done
File renamed without changes.
File renamed without changes.
Expand Up @@ -5,7 +5,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/coreos-inc/alm/apis"
"github.com/coreos-inc/alm/pkg/apis"
)

var (
Expand Down
Expand Up @@ -3,7 +3,7 @@ package v1alpha1
import (
"testing"

"github.com/coreos-inc/alm/apis"
"github.com/coreos-inc/alm/pkg/apis"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down
Expand Up @@ -3,7 +3,7 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

CSVv1alpha1 "github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
CSVv1alpha1 "github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

const (
Expand Down
Expand Up @@ -3,7 +3,7 @@ package v1alpha1
import (
"testing"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
"github.com/coreos/go-semver/semver"
"github.com/stretchr/testify/require"
)
Expand Down
Expand Up @@ -3,7 +3,7 @@ package v1alpha1
import (
"testing"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
"github.com/coreos/go-semver/semver"
"github.com/stretchr/testify/require"
)
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -5,7 +5,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/coreos-inc/alm/apis"
"github.com/coreos-inc/alm/pkg/apis"
)

var (
Expand Down
Expand Up @@ -3,7 +3,7 @@ package v1alpha1
import (
"testing"

"github.com/coreos-inc/alm/apis"
"github.com/coreos-inc/alm/pkg/apis"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down
File renamed without changes.
Expand Up @@ -5,7 +5,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/coreos-inc/alm/apis"
"github.com/coreos-inc/alm/pkg/apis"
)

var (
Expand Down
Expand Up @@ -3,7 +3,7 @@ package v1alpha1
import (
"testing"

"github.com/coreos-inc/alm/apis"
"github.com/coreos-inc/alm/pkg/apis"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down
Expand Up @@ -11,7 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer/json"
k8sjson "k8s.io/apimachinery/pkg/runtime/serializer/json"

csvv1alpha1 "github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
csvv1alpha1 "github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

const (
Expand Down
Expand Up @@ -12,7 +12,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer/json"

csvv1alpha1 "github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
csvv1alpha1 "github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

func stepCRD(name, kind, group, version string) v1beta1.CustomResourceDefinition {
Expand Down
Expand Up @@ -6,9 +6,9 @@ import (
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/coreos-inc/alm/apis/alphacatalogentry/v1alpha1"
csvv1alpha1 "github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/client"
"github.com/coreos-inc/alm/pkg/apis/alphacatalogentry/v1alpha1"
csvv1alpha1 "github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/client"
)

// CatalogSync tracks information about the last time the catalog was synced to the cluster
Expand Down
Expand Up @@ -11,8 +11,8 @@ import (

"reflect"

"github.com/coreos-inc/alm/apis/alphacatalogentry/v1alpha1"
csvv1alpha1 "github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/alphacatalogentry/v1alpha1"
csvv1alpha1 "github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

type EntryMatcher struct{ entry v1alpha1.AlphaCatalogEntry }
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion catalog/manifest.go → pkg/catalog/manifest.go
Expand Up @@ -7,7 +7,7 @@ import (
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/client-go/kubernetes/scheme"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

// LoadCRDFromFile is a utility function for loading the CRD schemas.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion catalog/mem.go → pkg/catalog/mem.go
Expand Up @@ -8,7 +8,7 @@ import (
log "github.com/sirupsen/logrus"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

// InMem - catalog source implementation that stores the data in memory in golang maps
Expand Down
2 changes: 1 addition & 1 deletion catalog/mem_test.go → pkg/catalog/mem_test.go
Expand Up @@ -10,7 +10,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

// compareResources compares resource equality then prints a diff for easier debugging
Expand Down
2 changes: 1 addition & 1 deletion catalog/types.go → pkg/catalog/types.go
Expand Up @@ -3,7 +3,7 @@ package catalog
import (
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

// Catalog Source
Expand Down
Expand Up @@ -4,7 +4,7 @@
package catalog

import (
v1alpha1 "github.com/coreos-inc/alm/apis/alphacatalogentry/v1alpha1"
v1alpha1 "github.com/coreos-inc/alm/pkg/apis/alphacatalogentry/v1alpha1"
gomock "github.com/golang/mock/gomock"
)

Expand Down
Expand Up @@ -11,7 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest"

"github.com/coreos-inc/alm/apis/alphacatalogentry/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/alphacatalogentry/v1alpha1"
)

type AlphaCatalogEntryInterface interface {
Expand Down
Expand Up @@ -17,9 +17,9 @@ import (
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/client-go/rest"

"github.com/coreos-inc/alm/apis"
"github.com/coreos-inc/alm/apis/alphacatalogentry/v1alpha1"
csvv1alpha1 "github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis"
"github.com/coreos-inc/alm/pkg/apis/alphacatalogentry/v1alpha1"
csvv1alpha1 "github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

func mockClient(t *testing.T, ts *httptest.Server) *AlphaCatalogEntryClient {
Expand Down
Expand Up @@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
)

type ClusterServiceVersionInterface interface {
Expand Down
Expand Up @@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest"

"github.com/coreos-inc/alm/apis/installplan/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis/installplan/v1alpha1"
)

type InstallPlanInterface interface {
Expand Down
File renamed without changes.
Expand Up @@ -4,7 +4,7 @@
package client

import (
v1alpha1 "github.com/coreos-inc/alm/apis/installplan/v1alpha1"
v1alpha1 "github.com/coreos-inc/alm/pkg/apis/installplan/v1alpha1"
gomock "github.com/golang/mock/gomock"
)

Expand Down
10 changes: 7 additions & 3 deletions install/deployment.go → pkg/install/deployment.go
Expand Up @@ -10,9 +10,9 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/coreos-inc/alm/apis"
"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/client"
"github.com/coreos-inc/alm/pkg/apis"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/client"
)

const (
Expand Down Expand Up @@ -110,6 +110,10 @@ func (i *StrategyDeploymentInstaller) Install(s Strategy) error {
}
}

//existingDeployments, err := i.strategyClient.GetOwnedDeployments(i.ownerMeta)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this in a follow on PR please.

//if err != nil {
// return fmt.Errorf("query for existing deployments failed: %s", err)
//}
for _, spec := range strategy.DeploymentSpecs {
dep := v1beta1.Deployment{Spec: spec}
dep.SetNamespace(i.ownerMeta.Namespace)
Expand Down
4 changes: 2 additions & 2 deletions install/deployment_test.go → pkg/install/deployment_test.go
Expand Up @@ -13,8 +13,8 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/coreos-inc/alm/apis"
"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/apis"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand Down
4 changes: 2 additions & 2 deletions install/resolver.go → pkg/install/resolver.go
Expand Up @@ -7,8 +7,8 @@ import (
opClient "github.com/coreos-inc/operator-client/pkg/client"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/client"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/client"
)

type Strategy interface {
Expand Down
8 changes: 4 additions & 4 deletions operators/alm/operator.go → pkg/operators/alm/operator.go
Expand Up @@ -9,10 +9,10 @@ import (
"k8s.io/apimachinery/pkg/fields"
"k8s.io/client-go/tools/cache"

"github.com/coreos-inc/alm/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/client"
"github.com/coreos-inc/alm/install"
"github.com/coreos-inc/alm/queueinformer"
"github.com/coreos-inc/alm/pkg/apis/clusterserviceversion/v1alpha1"
"github.com/coreos-inc/alm/pkg/client"
"github.com/coreos-inc/alm/pkg/install"
"github.com/coreos-inc/alm/pkg/queueinformer"
)

var ErrRequirementsNotMet = errors.New("requirements were not met")
Expand Down