forked from Azure/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix df check and add unit test (#77)
- Loading branch information
1 parent
03a376e
commit e51eb49
Showing
5 changed files
with
67 additions
and
5 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
24 changes: 24 additions & 0 deletions
24
src/k8s-extension/azext_k8s_extension/tests/latest/MockClasses.py
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,24 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
|
||
from azure.cli.core import AzCommandsLoader | ||
|
||
|
||
class MockCommand: | ||
def __init__(self): | ||
self.cli_ctx = MockCLIContext() | ||
|
||
class MockCLIContext: | ||
def __init__(self): | ||
self.cloud = MockCloud() | ||
|
||
class MockCloud: | ||
def __init__(self): | ||
self.endpoints = Endpoints() | ||
|
||
class Endpoints: | ||
def __init__(self): | ||
self.resource_manager = "" |
38 changes: 38 additions & 0 deletions
38
src/k8s-extension/azext_k8s_extension/tests/latest/test_custom.py
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,38 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import os | ||
from typing import no_type_check | ||
import unittest | ||
|
||
from .MockClasses import MockCLIContext, MockCommand | ||
from azext_k8s_extension.custom import is_dogfood_cluster | ||
|
||
|
||
class TestIsDogfoodCluster(unittest.TestCase): | ||
def test_dogfood_cluster(self): | ||
cmd = MockCommand() | ||
cmd.cli_ctx.cloud.endpoints.resource_manager = "https://api-dogfood.resources.windows-int.net" | ||
assert is_dogfood_cluster(cmd) | ||
|
||
def test_dogfood_cluster_with_slash(self): | ||
cmd = MockCommand() | ||
cmd.cli_ctx.cloud.endpoints.resource_manager = "https://api-dogfood.resources.windows-int.net/" | ||
assert is_dogfood_cluster(cmd) | ||
|
||
def test_longer_hostname(self): | ||
cmd = MockCommand() | ||
cmd.cli_ctx.cloud.endpoints.resource_manager = "https://api-dogfood.resources.windows-int.otherwebsite.net/" | ||
assert not is_dogfood_cluster(cmd) | ||
|
||
def malformed_url(self): | ||
cmd = MockCommand() | ||
cmd.cli_ctx.cloud.endpoints.resource_manager = "htmalformed~2987493" | ||
assert not is_dogfood_cluster(cmd) | ||
|
||
def test_prod_cluster(self): | ||
cmd = MockCommand() | ||
cmd.cli_ctx.cloud.endpoints.resource_manager = "https://management.azure.com" | ||
assert not is_dogfood_cluster(cmd) |
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