-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
464bbfa
commit 114757f
Showing
8 changed files
with
295 additions
and
50 deletions.
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
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,95 @@ | ||
package creds | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_NewForjValue(t *testing.T) { | ||
t.Log("Expecting NewForjValue to properly initialized the ForjValue object.") | ||
assert := assert.New(t) | ||
|
||
// ------------- call the function | ||
v := NewForjValue("forjj", "value") | ||
|
||
// -------------- testing | ||
when := "when a new ForjValue is set" | ||
if assert.NotNilf(v, "Expected ForjValue to be returned %s", when) { | ||
assert.Equalf("value", v.value, "Expected value to be properly set %s", when) | ||
assert.Equalf("forjj", v.source, "Expected source to be set properly %s", when) | ||
if assert.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
assert.Lenf(v.resource, 0, "Expected resource to be empty %s", when) | ||
} | ||
} | ||
} | ||
|
||
func Test_ForjValue_Set(t *testing.T) { | ||
t.Log("Expecting ForjValue.Set to properly set the ForjValue object.") | ||
assert := assert.New(t) | ||
|
||
v := ForjValue{} | ||
// ------------- call the function | ||
v.Set("forjj", "value") | ||
|
||
// -------------- testing | ||
when := "when an empty ForjValue is set" | ||
assert.Equalf("value", v.value, "Expected value to be properly set %s", when) | ||
assert.Equalf("forjj", v.source, "Expected source to be set properly %s", when) | ||
if assert.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
assert.Lenf(v.resource, 0, "Expected resource to be empty %s", when) | ||
} | ||
|
||
// -------------- Update context | ||
v1 := NewForjValue("forjj", "value") | ||
|
||
// ------------- call the function | ||
v1.Set("blabla", "value1") | ||
|
||
// -------------- testing | ||
when = "when an existing ForjValue is set" | ||
if assert.NotNilf(v1, "Expected ForjValue to be returned %s", when) { | ||
assert.Equalf("value1", v1.value, "Expected value to be properly set to new value %s", when) | ||
assert.Equalf("blabla", v1.source, "Expected source to be set properly to new value %s", when) | ||
if assert.NotNilf(v1.resource, "Expected resource to be initialized %s", when) { | ||
assert.Lenf(v1.resource, 0, "Expected resource to be empty %s", when) | ||
} | ||
} | ||
} | ||
|
||
func Test_ForjValue_AddResource(t *testing.T) { | ||
t.Log("Expecting ForjValue.AddResource to properly set the ForjValue object resource list.") | ||
test := assert.New(t) | ||
|
||
v := ForjValue{} | ||
r := map[string]string{ | ||
"key": "value", | ||
} | ||
|
||
// ------------- call the function | ||
v.AddResource("key", "value") | ||
|
||
// -------------- testing | ||
when := "when a resource is added on an empty ForjValue." | ||
test.Emptyf(v.value, "Expected value to stay empty %s", when) | ||
test.Emptyf(v.source, "Expected source to stay empty %s", when) | ||
if test.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
test.Lenf(v.resource, 1, "Expected resource to be empty %s", when) | ||
test.Truef(reflect.DeepEqual(v.resource, r), "Expected resource to be conform %s", when) | ||
} | ||
// -------------- Update context | ||
r["key"] = "value2" | ||
|
||
// ------------- call the function | ||
v.AddResource("key", "value2") | ||
|
||
// -------------- testing | ||
when = "when a resource is updated." | ||
test.Emptyf(v.value, "Expected value to stay empty %s", when) | ||
test.Emptyf(v.source, "Expected source to stay empty %s", when) | ||
if test.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
test.Lenf(v.resource, 1, "Expected resource to be empty %s", when) | ||
test.Truef(reflect.DeepEqual(v.resource, r), "Expected resource to be conform %s", when) | ||
} | ||
} |
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,129 @@ | ||
package creds | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/forj-oss/goforjj" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_NewObjectsValue(t *testing.T) { | ||
t.Log("Expecting NewForjValue to properly initialized the ForjValue object.") | ||
assert := assert.New(t) | ||
value := goforjj.NewValueStruct("value") | ||
|
||
// ------------- call the function | ||
v := NewObjectsValue("forjj", value) | ||
|
||
// -------------- testing | ||
when := "when a new ObjectsValue is set" | ||
if assert.NotNilf(v, "Expected ObjectsValue to be returned %s", when) { | ||
if assert.NotNilf(v.value, "Expected ObjectValue to have a valid ValueStruct %s", when) { | ||
assert.Truef(v.value.Equal(value), "Expected value to be properly set %s", when) | ||
assert.Equalf("forjj", v.source, "Expected source to be set properly %s", when) | ||
if assert.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
assert.Lenf(v.resource, 0, "Expected resource to be empty %s", when) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func Test_ObjectsValue_Set(t *testing.T) { | ||
t.Log("Expecting ForjValue.Set to properly set the ForjValue object.") | ||
assert := assert.New(t) | ||
|
||
v := ObjectsValue{} | ||
value := goforjj.NewValueStruct("value") | ||
|
||
// ------------- call the function | ||
v.Set("forjj", value) | ||
|
||
// -------------- testing | ||
when := "when an empty ForjValue is set" | ||
if assert.NotNilf(v.value, "Expected ObjectValue to have a valid ValueStruct %s", when) { | ||
assert.Truef(v.value.Equal(value), "Expected value to be properly set %s", when) | ||
assert.Equalf("forjj", v.source, "Expected source to be set properly %s", when) | ||
if assert.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
assert.Lenf(v.resource, 0, "Expected resource to be empty %s", when) | ||
} | ||
} | ||
|
||
// -------------- Update context | ||
value.Set("value2") | ||
|
||
// -------------- testing | ||
when = "when the ValueStruct value has been updated outside" | ||
if assert.NotNilf(v.value, "Expected ObjectValue to have a valid ValueStruct %s", when) { | ||
assert.Falsef(v.value.Equal(value), "Expected value to be updated %s", when) | ||
assert.Equalf("forjj", v.source, "Expected source to be set properly %s", when) | ||
if assert.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
assert.Lenf(v.resource, 0, "Expected resource to be empty %s", when) | ||
} | ||
} | ||
|
||
// ------------- call the function | ||
v.Set("blabla", value) | ||
|
||
// -------------- testing | ||
when = "when an existing ObjectsValue is set" | ||
if assert.NotNilf(v, "Expected ObjectsValue to be returned %s", when) { | ||
assert.Truef(v.value.Equal(value), "Expected value to be properly set to new value %s", when) | ||
assert.Equalf("blabla", v.source, "Expected source to be set properly to new value %s", when) | ||
if assert.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
assert.Lenf(v.resource, 0, "Expected resource to be empty %s", when) | ||
} | ||
} | ||
|
||
// -------------- Update context | ||
v1 := NewObjectsValue("forjj", goforjj.NewValueStruct("value")) | ||
|
||
// ------------- call the function | ||
v1.Set("blabla", value) | ||
|
||
// -------------- testing | ||
when = "when an existing ObjectsValue is set" | ||
if assert.NotNilf(v1, "Expected ObjectsValue to be returned %s", when) { | ||
assert.Truef(v.value.Equal(value), "Expected value to be properly set to new value %s", when) | ||
assert.Equalf("blabla", v1.source, "Expected source to be set properly to new value %s", when) | ||
if assert.NotNilf(v1.resource, "Expected resource to be initialized %s", when) { | ||
assert.Lenf(v1.resource, 0, "Expected resource to be empty %s", when) | ||
} | ||
} | ||
} | ||
|
||
func Test_ObjectsValue_AddResource(t *testing.T) { | ||
t.Log("Expecting ForjValue.AddResource to properly set the ForjValue object resource list.") | ||
test := assert.New(t) | ||
|
||
v := ObjectsValue{} | ||
r := map[string]string{ | ||
"key": "value", | ||
} | ||
|
||
// ------------- call the function | ||
v.AddResource("key", "value") | ||
|
||
// -------------- testing | ||
when := "when a resource is added on an empty ForjValue." | ||
test.Emptyf(v.value, "Expected value to stay empty %s", when) | ||
test.Emptyf(v.source, "Expected source to stay empty %s", when) | ||
if test.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
test.Lenf(v.resource, 1, "Expected resource to be empty %s", when) | ||
test.Truef(reflect.DeepEqual(v.resource, r), "Expected resource to be conform %s", when) | ||
} | ||
// -------------- Update context | ||
r["key"] = "value2" | ||
|
||
// ------------- call the function | ||
v.AddResource("key", "value2") | ||
|
||
// -------------- testing | ||
when = "when a resource is updated." | ||
test.Emptyf(v.value, "Expected value to stay empty %s", when) | ||
test.Emptyf(v.source, "Expected source to stay empty %s", when) | ||
if test.NotNilf(v.resource, "Expected resource to be initialized %s", when) { | ||
test.Lenf(v.resource, 1, "Expected resource to be empty %s", when) | ||
test.Truef(reflect.DeepEqual(v.resource, r), "Expected resource to be conform %s", when) | ||
} | ||
} |
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.