@@ -7,11 +7,9 @@ import (
77 "os"
88 "testing"
99
10- "path/filepath"
11-
1210 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1311 "k8s.io/client-go/kubernetes"
14- "k8s.io/client-go/tools/clientcmd "
12+ "k8s.io/client-go/rest "
1513)
1614
1715// list of common Harbor components.
@@ -26,8 +24,8 @@ var HarborComponentNames = []string{
2624
2725func Test_scs_0212_registry_standard_test (t * testing.T ) {
2826 // Set up the Kubernetes client
29- // config, err := rest.InClusterConfig()
30- config , err := clientcmd .BuildConfigFromFlags ("" , filepath .Join (homeDir (), ".kube" , "config" ))
27+ config , err := rest .InClusterConfig ()
28+ // config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(homeDir(), ".kube", "config"))
3129 if err != nil {
3230 log .Fatalf ("Failed to create rest config: %v" , err )
3331 }
@@ -53,6 +51,7 @@ func Test_scs_0212_registry_standard_test(t *testing.T) {
5351// check deployments for the registry
5452func checkDeployments (clientset * kubernetes.Clientset ) error {
5553 deployments , err := clientset .AppsV1 ().Deployments ("" ).List (context .TODO (), v1.ListOptions {})
54+ harborDeployments := 0
5655 if err != nil {
5756 return fmt .Errorf ("failed to list deployments: %v" , err )
5857 }
@@ -61,15 +60,22 @@ func checkDeployments(clientset *kubernetes.Clientset) error {
6160 for _ , componentName := range HarborComponentNames {
6261 if containsString (deployment .Name , componentName ) {
6362 fmt .Printf ("Found Harbor deployment: %s in namespace: %s\n " , deployment .Name , deployment .Namespace )
63+ harborDeployments ++
6464 }
6565 }
6666 }
67+ if harborDeployments > 0 {
68+ fmt .Printf ("Harbor deployments found\n " )
69+ } else {
70+ fmt .Printf ("Harbor was not found in deployments\n " )
71+ }
6772 return nil
6873}
6974
7075// check services for the registry components
7176func checkServices (clientset * kubernetes.Clientset ) error {
7277 services , err := clientset .CoreV1 ().Services ("" ).List (context .TODO (), v1.ListOptions {})
78+ harborServices := 0
7379 if err != nil {
7480 return fmt .Errorf ("failed to list services: %v" , err )
7581 }
@@ -78,9 +84,15 @@ func checkServices(clientset *kubernetes.Clientset) error {
7884 for _ , componentName := range HarborComponentNames {
7985 if containsString (service .Name , componentName ) {
8086 fmt .Printf ("Found Harbor service: %s in namespace: %s\n " , service .Name , service .Namespace )
87+ harborServices ++
8188 }
8289 }
8390 }
91+ if harborServices > 0 {
92+ fmt .Printf ("Harbor services found\n " )
93+ } else {
94+ fmt .Printf ("Harbor was not found services\n " )
95+ }
8496 return nil
8597}
8698
@@ -91,6 +103,7 @@ func containsString(str, substr string) bool {
91103
92104func homeDir () string {
93105 if h := os .Getenv ("HOME" ); h != "" {
106+ println (h )
94107 return h
95108 }
96109 return ""
0 commit comments