forked from containers/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src,test/system: Respect configuration file in system tests
Commit 20f4f68 added support for configuration files. If keys in the configuration file were set the system test suite would not honor them. This puts additional strain on distributors overriding the default settings. This solves the problem by creating a new hidden command in Toolbx that provides interface for getting some information Toolbx uses under-the-hood (e.g., the default container name, image). This commit does not change the way images are cached in the system test suite. In case an additional image is needed, the tests still need to be patched. Fixes containers#959 containers#1050
- Loading branch information
1 parent
f779c79
commit 73cef2d
Showing
8 changed files
with
238 additions
and
26 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,128 @@ | ||
/* | ||
* Copyright © 2022 Ondřej Míchal | ||
* | ||
* 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 ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/containers/toolbox/pkg/utils" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type ResolveFunc func([]string) error | ||
|
||
type RequestType struct { | ||
ArgsN int | ||
Resolve ResolveFunc | ||
} | ||
|
||
var ( | ||
testFlags struct { | ||
requestType string | ||
} | ||
|
||
requestTypes = map[string]RequestType{ | ||
"config-key": { | ||
1, | ||
resolveConfigKey, | ||
}, | ||
"default-container-name": { | ||
0, | ||
resolveDefaultContainerName, | ||
}, | ||
"default-image": { | ||
0, | ||
resolveDefaultImage, | ||
}, | ||
} | ||
) | ||
|
||
var testCmd = &cobra.Command{ | ||
Use: "__test", | ||
Short: "List existing toolbox containers and images", | ||
RunE: test, | ||
Hidden: true, | ||
ValidArgsFunction: completionEmpty, | ||
} | ||
|
||
func init() { | ||
flags := testCmd.Flags() | ||
|
||
flags.StringVar(&testFlags.requestType, | ||
"type", | ||
"", | ||
"type of data to be processed/retrieved") | ||
|
||
rootCmd.AddCommand(testCmd) | ||
} | ||
|
||
func test(cmd *cobra.Command, args []string) error { | ||
if !cmd.Flag("type").Changed { | ||
return errors.New("flag --type has to be provided") | ||
} | ||
|
||
requestType, ok := requestTypes[testFlags.requestType] | ||
if !ok { | ||
return fmt.Errorf("request type %s is not known", testFlags.requestType) | ||
} | ||
|
||
if requestType.ArgsN != len(args) { | ||
return fmt.Errorf("request type %s requires %d arguments", testFlags.requestType, requestType.ArgsN) | ||
} | ||
|
||
logrus.Debugf("Resolving request %s with arguments: %s", testFlags.requestType, args) | ||
|
||
resolve := requestType.Resolve | ||
if err := resolve(args); err != nil { | ||
return fmt.Errorf("failed to resolve request %s: %s", testFlags.requestType, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resolveConfigKey(args []string) error { | ||
fmt.Print(viper.GetString(args[0])) | ||
return nil | ||
} | ||
|
||
func resolveDefaultContainerName(_ []string) error { | ||
containerName, _, _, err := utils.ResolveContainerAndImageNames("", "", "", "") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Print(containerName) | ||
return nil | ||
} | ||
|
||
func resolveDefaultImage(_ []string) error { | ||
_, image, release, err := utils.ResolveContainerAndImageNames("", "", "", "") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
image, err = utils.GetFullyQualifiedImageFromDistros(image, release) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Print(image) | ||
return 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
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
Oops, something went wrong.