-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from k8sgpt-ai/feat/unit-testing-example
- Loading branch information
Showing
7 changed files
with
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Run tests | ||
|
||
on: [push] | ||
|
||
env: | ||
GO_VERSION: "~1.20" | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
|
||
- name: Test | ||
run: go test -v ./... |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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 TestServiceAnalzyer(t *testing.T) { | ||
|
||
clientset := fake.NewSimpleClientset(&v1.Endpoints{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "example", | ||
Namespace: "default", | ||
Annotations: map[string]string{}, | ||
}, | ||
}, | ||
&v1.Service{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "example", | ||
Namespace: "default", | ||
Annotations: map[string]string{}, | ||
}, | ||
Spec: v1.ServiceSpec{ | ||
Selector: map[string]string{ | ||
"app": "example", | ||
}, | ||
}}) | ||
|
||
serviceAnalyzer := ServiceAnalyzer{} | ||
var analysisResults []Analysis | ||
serviceAnalyzer.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