-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[testing] - add more coverage (#194)
* add tests for filter and version * exclude mock package from coverage since it's autogenerated * add helpers test * exclude autogenerated deepcopy from coverage
- Loading branch information
1 parent
98de934
commit b67426d
Showing
9 changed files
with
138 additions
and
8 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
.idea | ||
bin/* | ||
kind-logs-* | ||
cover.out | ||
cover.out* | ||
kubeconfig* | ||
.devbox/* | ||
docs/book | ||
|
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
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,54 @@ | ||
package util | ||
|
||
import "testing" | ||
|
||
func TestString(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
filter Filter | ||
expectErr bool | ||
}{{ | ||
name: "success ID", | ||
filter: Filter{ | ||
ID: Pointer(123), | ||
Label: "", | ||
Tags: nil, | ||
}, | ||
expectErr: false, | ||
}, { | ||
name: "success label", | ||
filter: Filter{ | ||
ID: nil, | ||
Label: "test", | ||
Tags: nil, | ||
}, | ||
expectErr: false, | ||
}, { | ||
name: "success tags", | ||
filter: Filter{ | ||
ID: nil, | ||
Label: "", | ||
Tags: []string{"testtag"}, | ||
}, | ||
expectErr: false, | ||
}, { | ||
name: "failure unmarshal", | ||
filter: Filter{ | ||
ID: nil, | ||
Label: "", | ||
Tags: []string{}, | ||
}, | ||
expectErr: true, | ||
}} | ||
for _, tt := range tests { | ||
testcase := tt | ||
t.Run(testcase.name, func(t *testing.T) { | ||
t.Parallel() | ||
_, err := testcase.filter.String() | ||
if testcase.expectErr && err != nil { | ||
t.Error("expected err but got nil") | ||
} | ||
}) | ||
} | ||
} |
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,51 @@ | ||
package util | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/linode/linodego" | ||
) | ||
|
||
func TestIgnoreLinodeAPIError(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
err error | ||
code int | ||
shouldFilter bool | ||
}{{ | ||
name: "Not Linode API error", | ||
err: errors.New("foo"), | ||
code: 0, | ||
shouldFilter: false, | ||
}, { | ||
name: "Ignore not found Linode API error", | ||
err: linodego.Error{ | ||
Response: nil, | ||
Code: 400, | ||
Message: "not found", | ||
}, | ||
code: 400, | ||
shouldFilter: true, | ||
}, { | ||
name: "Don't ignore not found Linode API error", | ||
err: linodego.Error{ | ||
Response: nil, | ||
Code: 400, | ||
Message: "not found", | ||
}, | ||
code: 500, | ||
shouldFilter: false, | ||
}} | ||
for _, tt := range tests { | ||
testcase := tt | ||
t.Run(testcase.name, func(t *testing.T) { | ||
t.Parallel() | ||
err := IgnoreLinodeAPIError(testcase.err, testcase.code) | ||
if testcase.shouldFilter && err != nil { | ||
t.Error("expected err but got nil") | ||
} | ||
}) | ||
} | ||
} |
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,11 @@ | ||
package version | ||
|
||
import "testing" | ||
|
||
func TestVersion(t *testing.T) { | ||
t.Parallel() | ||
vers := GetVersion() | ||
if vers != "dev" { | ||
t.Errorf("unset version should be dev, got %s", vers) | ||
} | ||
} |