Skip to content

Commit

Permalink
improvement for TestOptOutOptIn
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelina Nikiforova committed Jan 20, 2020
1 parent 32427f5 commit 6065fb9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test-unit:
.PHONY: test-unit

test-e2e:
go test ./test/integration $(TEST_OPTIONS)
go test ./test/integration -timeout 1h $(TEST_OPTIONS)
.PHONY: test-e2e

vendor:
Expand Down
28 changes: 27 additions & 1 deletion test/integration/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package integration
import (
"encoding/json"
"testing"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
)

// Check if opt-in/opt-out works
Expand Down Expand Up @@ -54,12 +56,36 @@ func TestOptOutOptIn(t *testing.T) {
resourceVersion := latestSecret.GetResourceVersion()
pullSecret.SetResourceVersion(resourceVersion) // need to update the version, otherwise operation is not permitted

_, err = clientset.CoreV1().Secrets("openshift-config").Update(pullSecret)
errConfig := wait.PollImmediate(5*time.Second, 5*time.Minute, func() (bool, error) {
objs := map[string]interface{}{}
errUnmarshals := json.Unmarshal([]byte(pullSecret.Data[".dockerconfigjson"]), &objs)
if errUnmarshals != nil {
t.Fatal(errUnmarshal.Error())
}
for key := range objs["auths"].(map[string]interface{}) {
if key == "cloud.openshift.com" {
return true, nil
}
}
return false, nil
})
t.Log(errConfig)

newSecret, err := clientset.CoreV1().Secrets("openshift-config").Update(pullSecret)
if err != nil {
t.Fatal(err.Error())
}
t.Logf("%v\n", newSecret)

// Check if reports are uploaded - Logs show that insights-operator is enabled and reports are uploaded
restartInsightsOperator(t)
errDisabled := wait.PollImmediate(1*time.Second, 10*time.Minute, func() (bool, error) {
insightsDisabled := isOperatorDisabled(t, clusterOperatorInsights())
if insightsDisabled {
return false, nil
}
return true, nil
})
t.Log(errDisabled)
checkPodsLogs(t, clientset, "Successfully reported")
}
18 changes: 17 additions & 1 deletion test/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,27 @@ func isOperatorDegraded(t *testing.T, operator *configv1.ClusterOperator) bool {
for _, condition := range statusConditions {
if condition.Type == "Degraded" {
if condition.Status != "True" {
t.Log("Insights is not degraded")
t.Log("Operator is not degraded")
return false
}
}
}
t.Log("Operator is degraded")
return true
}

func isOperatorDisabled(t *testing.T, operator *configv1.ClusterOperator) bool {
statusConditions := operator.Status.Conditions

for _, condition := range statusConditions {
if condition.Type == "Disabled" {
if condition.Status != "True" {
t.Log("Operator is not Disabled")
return false
}
}
}
t.Log("Operator is disabled")
return true
}

Expand Down

0 comments on commit 6065fb9

Please sign in to comment.