forked from argoproj-labs/argocd-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Julia Teslia <[email protected]>
- Loading branch information
Julia Teslia
committed
Apr 1, 2024
1 parent
970ee78
commit 81c9e17
Showing
9 changed files
with
540 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package argoutil | ||
|
||
/*import ( | ||
argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1" | ||
"github.com/argoproj-labs/argocd-operator/common" | ||
"k8s.io/client-go/rest" | ||
"reflect" | ||
"testing" | ||
"k8s.io/client-go/kubernetes/fake" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
) | ||
func TestVerifyAPI(t *testing.T) { | ||
k8s := fake.NewSimpleClientset() | ||
config.GetConfig = func() (*rest.Config, error) { | ||
return &rest.Config{}, nil | ||
} | ||
defer func() { | ||
config.GetConfig = config.Rea | ||
}() | ||
type args struct { | ||
cr *argoproj.ArgoCD | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]string | ||
}{ | ||
{ | ||
name: "simple annotations", | ||
args: args{ | ||
&argoproj.ArgoCD{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "foo", | ||
Namespace: "bar", | ||
}, | ||
}, | ||
}, | ||
want: map[string]string{ | ||
"argocds.argoproj.io/name": "foo", | ||
"argocds.argoproj.io/namespace": "bar", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := common.DefaultAnnotations(tt.args.cr.Name, tt.args.cr.Namespace); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("DefaultAnnotations() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package argoutil | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
"testing" | ||
) | ||
|
||
func TestGenerateArgoAdminPassword(t *testing.T) { | ||
password, err := GenerateArgoAdminPassword() | ||
assert.NoError(t, err) | ||
assert.NotNil(t, password) | ||
} | ||
|
||
func TestGenerateArgoServerSessionKey(t *testing.T) { | ||
password, err := GenerateArgoServerSessionKey() | ||
assert.NoError(t, err) | ||
assert.NotNil(t, password) | ||
} | ||
|
||
func TestHasArgoAdminPasswordChanged(t *testing.T) { | ||
t.Run("Admin Password Changed", func(t *testing.T) { | ||
old_admin_password, err := GenerateArgoAdminPassword() | ||
if err != nil { | ||
t.Errorf("Error when generating admin password") | ||
|
||
} | ||
old_password := &corev1.Secret{ | ||
Data: map[string][]byte{ | ||
"admin-password": old_admin_password, | ||
}, | ||
} | ||
|
||
new_admin_password, err := GenerateArgoAdminPassword() | ||
if err != nil { | ||
t.Errorf("Error when generating admin password") | ||
|
||
} | ||
new_password := &corev1.Secret{ | ||
Data: map[string][]byte{ | ||
"admin-password": new_admin_password, | ||
}, | ||
} | ||
|
||
got := HasArgoAdminPasswordChanged(old_password, new_password) | ||
if got != true { | ||
t.Errorf("HasAdminPasswordChanged() = %v, want true", got) | ||
} | ||
}) | ||
t.Run("Admin Password Not Changed", func(t *testing.T) { | ||
old_admin_password, err := GenerateArgoAdminPassword() | ||
if err != nil { | ||
t.Errorf("Error when generating admin password") | ||
|
||
} | ||
old_password := &corev1.Secret{ | ||
Data: map[string][]byte{ | ||
"admin-password": old_admin_password, | ||
}, | ||
} | ||
|
||
/*new_password := &corev1.Secret{ | ||
Data: map[string][]byte{ | ||
"admin-password": old_admin_password, | ||
}, | ||
}*/ | ||
|
||
got := HasArgoAdminPasswordChanged(old_password, old_password) | ||
if got != false { | ||
t.Errorf("HasAdminPasswordChanged() = %v, want false", got) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestBoolPtr(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
value bool | ||
}{ | ||
{"True", true}, | ||
{"False", false}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := BoolPtr(tt.value) | ||
if *got != tt.value { | ||
t.Errorf("BoolPtr() = %v", got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestLoadTemplateFile(t *testing.T) { | ||
t.Run("Simple Template", func(t *testing.T) { | ||
testfile, err := os.CreateTemp("", "testing") | ||
if err != nil { | ||
t.Errorf("Error creating temporary file: %v", err) | ||
} | ||
defer func(name string) { | ||
err := os.Remove(name) | ||
if err != nil { | ||
t.Errorf("Error removing temporary file: %v", err) | ||
} | ||
}(testfile.Name()) | ||
|
||
_, err = testfile.Write([]byte("Day and time entered: {{.Day}}, {{.Time}}.")) | ||
|
||
if err != nil { | ||
t.Errorf("Error wriing to temporary file: %v", err) | ||
} | ||
|
||
err = testfile.Close() | ||
if err != nil { | ||
t.Errorf("Error closing temporary file: %v", err) | ||
} | ||
|
||
params := map[string]string{ | ||
"Day": "Monday", | ||
"Time": "12.00", | ||
} | ||
|
||
result, err := LoadTemplateFile(testfile.Name(), params) | ||
|
||
if err != nil { | ||
t.Errorf("LoadTemplateFile() error = %v", err) | ||
} | ||
|
||
expected := "Day and time entered: Monday, 12.00." | ||
|
||
if result != expected { | ||
t.Errorf("LoadTemplateFile() result = %v, want %v", err, expected) | ||
} | ||
}) | ||
t.Run("Non-existent File", func(t *testing.T) { | ||
params := map[string]string{ | ||
"Day": "Monday", | ||
"Time": "12.00", | ||
} | ||
|
||
result, err := LoadTemplateFile("some_path", params) | ||
|
||
if err == nil { | ||
t.Errorf("LoadTemplateFile() should throw error because of non-existent template file") | ||
} | ||
|
||
expected := "" | ||
|
||
if result != expected { | ||
t.Errorf("LoadTemplateFile() result = %v, want %v", err, expected) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.