Skip to content

Commit

Permalink
fix remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed El-Sayed committed Dec 4, 2022
1 parent 30f7772 commit e973960
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: integration

on:
push:
branches: [ master, dev ]
Expand Down Expand Up @@ -29,7 +31,13 @@ jobs:
- name: Run tests
env:
NAMESPACE: ${{ matrix.namespace }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
make build
VERSION=$(cat ./version.txt)
docker build -t weaveworks/policy-agent:${VERSION} .
cd integration
bash deploy.sh
go test -v ./...
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v ./internal/... ./controllers/... ./pkg/... -coverprofile cover.out

##@ Build

Expand Down
3 changes: 2 additions & 1 deletion integration/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ echo "[*] Creating test cluster ..."
kind delete cluster --name test
kind create cluster --name test

kind load docker-image weaveworks/policy-agent:${VERSION} --name test

kubectl create namespace flux-system

echo "[*] Installing cert-manager ..."
Expand All @@ -18,4 +20,3 @@ kubectl apply -f data/state

echo "[*] Installing policy agent helm chart on namespace ${NAMESPACE} ..."
helm install policy-agent ../helm -n ${NAMESPACE} -f ../helm/values.yaml -f data/values.yaml --create-namespace --wait --timeout 60s

22 changes: 11 additions & 11 deletions integration/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package integration
import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
"time"

Expand All @@ -22,8 +24,12 @@ const (
missingOwnerLabelPolicy = "weave.policies.missing-owner-label"
)

func TestA(t *testing.T) {
config, err := clientcmd.BuildConfigFromFlags("", "/home/ahsayde/.kube/config")
func TestIntegration(t *testing.T) {
homeDir, err := os.UserHomeDir()
assert.Nil(t, err)

kubeConfigPath := filepath.Join(homeDir, ".kube", "config")
config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
if err != nil {
panic(err)
}
Expand All @@ -45,9 +51,7 @@ func TestA(t *testing.T) {
}

policies, err := listPolicies(ctx, cl)
if err != nil {
t.Fatal(err)
}
assert.Nil(t, err)

assert.Equal(t, len(policies.Items), 3)

Expand All @@ -66,9 +70,7 @@ func TestA(t *testing.T) {
}

events, err := listViolationEvents(ctx, cl, opts)
if err != nil {
t.Fatal(err)
}
assert.Nil(t, err)

assert.Equal(t, len(events.Items), 4)

Expand All @@ -86,9 +88,7 @@ func TestA(t *testing.T) {

t.Run("check admission results", func(t *testing.T) {
err := kubectl("apply", "-f", "data/resources/admission_test_resources.yaml")
if err == nil {
t.Error(err)
}
assert.NotNil(t, err)

time.Sleep(2 * time.Second)

Expand Down
2 changes: 1 addition & 1 deletion internal/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
TypeTerraform = "Terraform"
TypeTFAdmission = "TFAdmission"
)

type Response struct {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func main() {
validator := validation.NewOPAValidator(
policiesSource,
false,
terraform.TypeTerraform,
terraform.TypeTFAdmission,
config.AccountID,
config.ClusterID,
terraformSinks...,
Expand Down

0 comments on commit e973960

Please sign in to comment.