-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding unit testing and example
Signed-off-by: AlexsJones <[email protected]>
- Loading branch information
1 parent
b643637
commit 35b838b
Showing
5 changed files
with
55 additions
and
4 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
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,45 @@ | ||
package analyzer | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes" | ||
"github.com/magiconair/properties/assert" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
func TestPodAnalzyer(t *testing.T) { | ||
|
||
clientset := fake.NewSimpleClientset(&v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "example", | ||
Namespace: "default", | ||
Annotations: map[string]string{}, | ||
}, | ||
Status: v1.PodStatus{ | ||
Phase: v1.PodPending, | ||
Conditions: []v1.PodCondition{ | ||
{ | ||
Type: v1.PodScheduled, | ||
Reason: "Unschedulable", | ||
Message: "0/1 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.", | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
podAnalyzer := PodAnalyzer{} | ||
var analysisResults []Analysis | ||
podAnalyzer.RunAnalysis(context.Background(), | ||
&AnalysisConfiguration{ | ||
Namespace: "default", | ||
}, | ||
&kubernetes.Client{ | ||
Client: clientset, | ||
}, nil, &analysisResults) | ||
|
||
assert.Equal(t, len(analysisResults), 1) | ||
} |
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