Esempio n. 1
0
 def test_valid_flag(project: Project, datadir) -> None:
     project.config["flagFormat"] = r"flag\{[a-z]*\}"
     configloader = config.ConfigLoader(project)
     cfg, errors = configloader.check_config(datadir / "flag-format" /
                                             "valid" / "challenge.yml")
     assert cfg is not None
     assert errors is None
Esempio n. 2
0
 def test_invalid_flag(project: Project, datadir) -> None:
     project.config["flagFormat"] = r"flag\{[a-z]*\}"
     configloader = config.ConfigLoader(project)
     cfg, errors = configloader.check_config(datadir / "flag-format" /
                                             "invalid" / "challenge.yml")
     assert errors is not None
     assert cfg is None
     errors = list(errors)
     error_messages = [str(e) for e in errors]
     assert len(errors) != 0
     assert 'Flag "flag{1234}" does not match the flag format' in error_messages
     assert sum(
         [1 for e in errors if isinstance(e, config.InvalidFlagError)]) == 1
Esempio n. 3
0
 def test_omnibus(project: Project, datadir) -> None:
     project.config["defaults"] = {
         "containers": {
             "resources": {
                 "limits": {
                     "cpu": "10m",
                     "memory": "10Mi"
                 },
                 "requests": {
                     "cpu": "10m",
                     "memory": "10Mi"
                 },
             }
         },
         "expose": {
             "foo": "bar"
         },
         "value": 100,
     }
     configloader = config.ConfigLoader(project)
     cfg1 = configloader.load_config(datadir / "defaults" / "1" /
                                     "challenge.yml")
     assert cfg1["value"] == 100
     assert cfg1["containers"]["main"] == {
         "image": "gcr.io/google-samples/hello-app",
         "resources": {
             "limits": {
                 "cpu": "10m",
                 "memory": "10Mi"
             },
             "requests": {
                 "cpu": "10m",
                 "memory": "10Mi"
             },
         },
         "ports": [80],
         "replicas": 1,
     }
     assert cfg1["containers"]["partial"] == {
         "image": "gcr.io/google-samples/hello-app",
         "resources": {
             "limits": {
                 "cpu": "20m",
                 "memory": "10Mi"
             },
             "requests": {
                 "cpu": "10m",
                 "memory": "10Mi"
             },
         },
         "ports": [80],
         "replicas": 1,
     }
     assert cfg1["expose"]["main"][0] == {
         "target": 80,
         "tcp": 31525,
         "foo": "bar"
     }
     assert cfg1["expose"]["partial"][0] == {
         "target": 80,
         "tcp": 31546,
         "foo": "baz",
     }
     cfg2 = configloader.load_config(datadir / "defaults" / "2" /
                                     "challenge.yml")
     assert cfg2["value"] == 100
Esempio n. 4
0
def configloader(project):
    return config.ConfigLoader(project)
Esempio n. 5
0
def configloader(datadir):
    project = Project(datadir)
    return config.ConfigLoader(project)