-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added few unit tests and PR workflow
- Loading branch information
Showing
7 changed files
with
170 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,29 @@ | ||
name: pr | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.20 | ||
|
||
- name: Go Build | ||
run: go build -v ./... | ||
|
||
- name: Go 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,16 +13,19 @@ jobs: | |
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.20 | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create PR in krew-index | ||
uses: rajatjindal/[email protected] |
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,63 @@ | ||
package pkg | ||
|
||
import "testing" | ||
|
||
func TestGetNodeTopologyInfo(t *testing.T) { | ||
type args struct { | ||
labels map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
region string | ||
zone string | ||
}{ | ||
{ | ||
name: "WithRegionAndZoneInfo", | ||
args: args{ | ||
labels: map[string]string{ | ||
TopologyRegionLabel: "us-east-1", | ||
TopologyZoneLabel: "us-east-1a", | ||
}, | ||
}, | ||
region: "us-east-1", | ||
zone: "us-east-1a", | ||
}, { | ||
name: "NoRegionAndZoneLabels", | ||
args: args{ | ||
labels: map[string]string{}, | ||
}, | ||
region: "", | ||
zone: "", | ||
}, { | ||
name: "WithOnlyRegionLabel", | ||
args: args{ | ||
labels: map[string]string{ | ||
TopologyRegionLabel: "us-east-1", | ||
}, | ||
}, | ||
region: "us-east-1", | ||
zone: "", | ||
}, { | ||
name: "WithOnlyZoneLabel", | ||
args: args{ | ||
labels: map[string]string{ | ||
TopologyZoneLabel: "us-east-1a", | ||
}, | ||
}, | ||
region: "", | ||
zone: "us-east-1a", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, got1 := GetNodeTopologyInfo(tt.args.labels) | ||
if got != tt.region { | ||
t.Errorf("GetNodeTopologyInfo() got = %v, region %v", got, tt.region) | ||
} | ||
if got1 != tt.zone { | ||
t.Errorf("GetNodeTopologyInfo() got1 = %v, zone %v", got1, tt.zone) | ||
} | ||
}) | ||
} | ||
} |
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,39 @@ | ||
package outputs | ||
|
||
import "testing" | ||
|
||
func TestTableOutput(t *testing.T) { | ||
type args struct { | ||
headers []string | ||
outputData [][]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
name: "GenericOutputTable", | ||
args: args{ | ||
headers: []string{"NAME", "VERSION", "OS", "ARCHITECTURE"}, | ||
outputData: [][]string{ | ||
{ | ||
"Node01", | ||
"1.25.6", | ||
"linux", | ||
"amd64", | ||
}, { | ||
"Node02", | ||
"1.25.6", | ||
"linux", | ||
"arm64", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
TableOutput(tt.args.headers, tt.args.outputData) | ||
}) | ||
} | ||
} |
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,35 @@ | ||
package utils | ||
|
||
import "testing" | ||
|
||
func TestPrettyByteSize(t *testing.T) { | ||
type args struct { | ||
b int64 | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "ValidByteInPrettyFormatInKiB", | ||
args: args{ | ||
b: 1024, | ||
}, | ||
want: "1.0KiB", | ||
}, { | ||
name: "ValidByteInPrettyFormatInGiB", | ||
args: args{ | ||
b: 1073741824, | ||
}, | ||
want: "1.0GiB", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := PrettyByteSize(tt.args.b); got != tt.want { | ||
t.Errorf("PrettyByteSize() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |