-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Unit testing for package
v1alpha1
(#34)
- Loading branch information
1 parent
80b665b
commit 7b338c8
Showing
3 changed files
with
72 additions
and
2 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,69 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestInstrumentationDefaultingWebhook(t *testing.T) { | ||
inst := &Instrumentation{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
AnnotationDefaultAutoInstrumentationJava: "java-img:1", | ||
AnnotationDefaultAutoInstrumentationNodeJS: "nodejs-img:1", | ||
AnnotationDefaultAutoInstrumentationPython: "python-img:1", | ||
AnnotationDefaultAutoInstrumentationDotNet: "dotnet-img:1", | ||
}, | ||
}, | ||
} | ||
inst.Default() | ||
assert.Equal(t, "java-img:1", inst.Spec.Java.Image) | ||
assert.Equal(t, "nodejs-img:1", inst.Spec.NodeJS.Image) | ||
assert.Equal(t, "python-img:1", inst.Spec.Python.Image) | ||
assert.Equal(t, "dotnet-img:1", inst.Spec.DotNet.Image) | ||
} | ||
|
||
func TestInstrumentationValidatingWebhook(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
err string | ||
inst Instrumentation | ||
}{ | ||
{ | ||
name: "argument is a number", | ||
inst: Instrumentation{ | ||
Spec: InstrumentationSpec{ | ||
Sampler: Sampler{ | ||
Type: ParentBasedTraceIDRatio, | ||
Argument: "0.99", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "argument is missing", | ||
inst: Instrumentation{ | ||
Spec: InstrumentationSpec{ | ||
Sampler: Sampler{ | ||
Type: ParentBasedTraceIDRatio, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
if test.err == "" { | ||
assert.Nil(t, test.inst.ValidateCreate()) | ||
assert.Nil(t, test.inst.ValidateUpdate(nil)) | ||
} else { | ||
err := test.inst.ValidateCreate() | ||
assert.Contains(t, err.Error(), test.err) | ||
err = test.inst.ValidateUpdate(nil) | ||
assert.Contains(t, err.Error(), test.err) | ||
} | ||
}) | ||
} | ||
} |
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