-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
launcher doctor subcommand #1197
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c3f6e13
WIP
4f26ded
Moar checkpoint
08b16d8
Working better
19bca9e
Cleanup with options
b0e27ad
Added some docs
7544d79
Rename things better and add a simple test.
2379326
Added arch
fcd35ca
Adding default paths
c50aaa7
Organixe path code
79763d5
process report
b24e994
Linter fail
b69e6d4
Windows paths
c793d21
Update cmd/launcher/paths.go
seejdev 251e022
Update cmd/launcher/doctor.go
seejdev 863e3dc
Apply suggestions from code review
seejdev 9c6fec2
Cleanup the parseOptions nonsense
e16f707
Merge branch 'main' into doctor
7501398
Using writers now
596052b
Bg color
b03a29d
Fixed windows
49879b0
Check version from TUF
bc07d16
Tabs
78ed079
Osquery
1f9137a
Fixing tests
446aefe
Integrated doctor into flare
ef5e2fd
Fixing some windows paths issues
be442df
Version checks don't fail when current not equal to target
fee7d9d
Merge branch 'main' into doctor
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,198 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/kolide/kit/version" | ||
"github.com/kolide/launcher/pkg/autoupdate" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
// We don't care about the actual CLI output | ||
doctorWriter = io.Discard | ||
} | ||
|
||
func TestRunCheckups(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
checkups []*checkup | ||
}{ | ||
{ | ||
name: "successful checkups", | ||
checkups: []*checkup{ | ||
{ | ||
name: "do nothing", | ||
check: func() (string, error) { | ||
return "", nil | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "failed checkup", | ||
checkups: []*checkup{ | ||
{ | ||
name: "do nothing", | ||
check: func() (string, error) { | ||
return "", nil | ||
}, | ||
}, | ||
{ | ||
name: "return error", | ||
check: func() (string, error) { | ||
return "", errors.New("checkup error") | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
runCheckups(tt.checkups) | ||
}) | ||
} | ||
} | ||
|
||
func TestCheckupPlatform(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
os string | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "supported", | ||
os: runtime.GOOS, | ||
expectedErr: false, | ||
}, | ||
{ | ||
name: "unsupported", | ||
os: "not-an-os", | ||
expectedErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
_, err := checkupPlatform(tt.os) | ||
if tt.expectedErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCheckupArch(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
os string | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "supported", | ||
os: runtime.GOARCH, | ||
expectedErr: false, | ||
}, | ||
{ | ||
name: "unsupported", | ||
os: "not-an-arch", | ||
expectedErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
_, err := checkupArch(tt.os) | ||
if tt.expectedErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCheckupRootDir(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
filepaths []string | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "present", | ||
filepaths: []string{"debug.json", "launcher.db", "osquery.db"}, | ||
expectedErr: false, | ||
}, | ||
{ | ||
name: "not present", | ||
filepaths: []string{"not-an-important-file"}, | ||
expectedErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
_, err := checkupRootDir(tt.filepaths) | ||
if tt.expectedErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCheckupVersion(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
updateChannel string | ||
tufServerURL string | ||
version version.Info | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "happy path", | ||
updateChannel: autoupdate.Stable.String(), | ||
tufServerURL: "https://tuf.kolide.com", | ||
version: version.Version(), | ||
expectedErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
_, err := checkupVersion(tt.updateChannel, tt.tufServerURL, tt.version) | ||
if tt.expectedErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, 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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, this is an interesting way to do this.