-
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.
- add Fprint* functions for PrintError, PrintSuccess, etc. - move actual config loading from NewConfig to LoadConfig to be able to easily load a test config for testing - rename NewHctl argument from "loadCfg" to "testing" and only load config from defined config paths if we're not in testing mode - add newTestingHctl to create Hctl instance for testing - add testCmd function to handle the work for all the cmd command testing
- Loading branch information
Showing
33 changed files
with
764 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 Fabian `xx4h` Sylvester | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/xx4h/hctl/pkg/hctltest" | ||
) | ||
|
||
func Test_newCmdBrightness(t *testing.T) { | ||
ms := hctltest.MockServer(t) | ||
h := newTestingHctl(t) | ||
if err := h.SetConfigValue("hub.url", ms.URL); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
var tests = map[string]cmdTest{ | ||
"set brightness": { | ||
"brightness light.livingroom_other 20", | ||
"(?m)^.*livingroom_other brightness set to 20%", | ||
"", | ||
}, | ||
} | ||
|
||
testCmd(t, h, tests) | ||
} |
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,33 @@ | ||
// Copyright 2024 Fabian `xx4h` Sylvester | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_newCmdConfigGet(t *testing.T) { | ||
h := newTestingHctl(t) | ||
|
||
var tests = map[string]cmdTest{ | ||
"get existing option": { | ||
"config get completion.short_names", | ||
"(?m)^OPTION\\s+VALUE$\n^completion.short_names\\s+true", | ||
"", | ||
}, | ||
} | ||
|
||
testCmd(t, h, tests) | ||
} |
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,33 @@ | ||
// Copyright 2024 Fabian `xx4h` Sylvester | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_newCmdConfigRem(t *testing.T) { | ||
h := newTestingHctl(t) | ||
|
||
var tests = map[string]cmdTest{ | ||
"rem completion.short_names": { | ||
"config remove device_map.g", | ||
"(?m)^.*Option `device_map.g` successfully removed", | ||
"", | ||
}, | ||
} | ||
|
||
testCmd(t, h, tests) | ||
} |
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,33 @@ | ||
// Copyright 2024 Fabian `xx4h` Sylvester | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_newCmdConfigSet(t *testing.T) { | ||
h := newTestingHctl(t) | ||
|
||
var tests = map[string]cmdTest{ | ||
"set completion.short_names option": { | ||
"config set completion.short_names false", | ||
"(?m)^.*Option `completion.short_names` successfully set to `false`", | ||
"", | ||
}, | ||
} | ||
|
||
testCmd(t, h, tests) | ||
} |
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 @@ | ||
// Copyright 2024 Fabian `xx4h` Sylvester | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/xx4h/hctl/pkg/hctltest" | ||
) | ||
|
||
func Test_newCmdList(t *testing.T) { | ||
ms := hctltest.MockServer(t) | ||
h := newTestingHctl(t) | ||
if err := h.SetConfigValue("hub.url", ms.URL); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
var tests = map[string]cmdTest{ | ||
"list services": { | ||
"list services", | ||
`^.*Services`, | ||
"", | ||
}, | ||
"list services with play_media": { | ||
"list services -s play_media", | ||
`(?m)^.*Services.*\n.*media_player.*\n.*play_media`, | ||
"", | ||
}, | ||
"list entities": { | ||
"list entities", | ||
`^.*States`, | ||
"", | ||
}, | ||
"list entities of domain media_player": { | ||
"list entities -d media_player", | ||
`^.*States.*\n.*media_player.*\n.*player1.*\n.*player2`, | ||
"", | ||
}, | ||
} | ||
|
||
testCmd(t, h, tests) | ||
} |
Oops, something went wrong.